Skip to content

Commit 8141e0a

Browse files
kiranchandramohanbryanpkc
authored andcommitted
Changes for reassoc attributes
This patch adds code to generate the driver flags so that llvm bridge in flang2 can generate the nsz, reassoc attributes to arithmetic instructions. Also included is a testcase.
1 parent 4d105b5 commit 8141e0a

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

clang/lib/Driver/ToolChains/ClassicFlang.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
6969
bool NeedIEEE = true;
7070
bool NeedFastMath = false;
7171
bool NeedRelaxedMath = false;
72+
bool AssociativeMath = false;
73+
bool SignedZeros = true;
7274

7375
// Check number of inputs for sanity. We need at least one input.
7476
assert(Inputs.size() >= 1 && "Must have at least one input.");
@@ -509,21 +511,35 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
509511
*/
510512
for(Arg *A: Args.filtered(options::OPT_ffast_math, options::OPT_fno_fast_math,
511513
options::OPT_Ofast, options::OPT_Kieee_off,
512-
options::OPT_Kieee_on, options::OPT_frelaxed_math)) {
514+
options::OPT_Kieee_on, options::OPT_frelaxed_math,
515+
options::OPT_fassociative_math,
516+
options::OPT_fno_associative_math,
517+
options::OPT_fsigned_zeros,
518+
options::OPT_fno_signed_zeros)) {
513519
if (A->getOption().matches(options::OPT_ffast_math) ||
514520
A->getOption().matches(options::OPT_Ofast)) {
515521
NeedIEEE = NeedRelaxedMath = false;
516522
NeedFastMath = true;
517523
} else if (A->getOption().matches(options::OPT_Kieee_on)) {
518-
NeedFastMath = NeedRelaxedMath = false;
519-
NeedIEEE = true;
524+
NeedFastMath = NeedRelaxedMath = AssociativeMath = false;
525+
NeedIEEE = SignedZeros = true;
520526
} else if (A->getOption().matches(options::OPT_frelaxed_math)) {
521527
NeedFastMath = NeedIEEE = false;
522528
NeedRelaxedMath = true;
523529
} else if (A->getOption().matches(options::OPT_fno_fast_math)) {
524530
NeedFastMath = false;
525531
} else if (A->getOption().matches(options::OPT_Kieee_off)) {
526532
NeedIEEE = false;
533+
} else if (A->getOption().matches(options::OPT_fassociative_math)) {
534+
AssociativeMath = true;
535+
NeedIEEE = SignedZeros = false;
536+
} else if (A->getOption().matches(options::OPT_fno_associative_math)) {
537+
AssociativeMath = false;
538+
} else if (A->getOption().matches(options::OPT_fsigned_zeros)) {
539+
SignedZeros = true;
540+
AssociativeMath = false;
541+
} else if (A->getOption().matches(options::OPT_fno_signed_zeros)) {
542+
SignedZeros = NeedIEEE = false;
527543
}
528544
A->claim();
529545
}
@@ -1011,6 +1027,17 @@ void ClassicFlang::ConstructJob(Compilation &C, const JobAction &JA,
10111027
LowerCmdArgs.push_back("-x"); LowerCmdArgs.push_back("189"); LowerCmdArgs.push_back("0x10");
10121028
LowerCmdArgs.push_back("-y"); LowerCmdArgs.push_back("189"); LowerCmdArgs.push_back("0x4000000");
10131029

1030+
if (!SignedZeros) {
1031+
LowerCmdArgs.push_back("-x");
1032+
LowerCmdArgs.push_back("216");
1033+
LowerCmdArgs.push_back("0x8");
1034+
}
1035+
if (AssociativeMath) {
1036+
LowerCmdArgs.push_back("-x");
1037+
LowerCmdArgs.push_back("216");
1038+
LowerCmdArgs.push_back("0x10");
1039+
}
1040+
10141041
// Remove "noinline" attriblute
10151042
LowerCmdArgs.push_back("-x"); LowerCmdArgs.push_back("183"); LowerCmdArgs.push_back("0x10");
10161043

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
! REQUIRES: classic_flang
2+
3+
! Tests for flags which generate nsw, reassoc attributes
4+
5+
! RUN: %flang -Kieee %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
6+
! RUN: %flang -Knoieee %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
7+
! RUN: %flang -ffast-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
8+
! RUN: %flang -fno-fast-math %s -### 2>&1 | FileCheck --check-prefixes=NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
9+
! RUN: %flang -frelaxed-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,RELAXED,NO_REASSOC,NO_NSZ %s
10+
! RUN: %flang -fassociative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,REASSOC_NSZ %s
11+
! RUN: %flang -fno-associative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
12+
! RUN: %flang -fsigned-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
13+
! RUN: %flang -fno-signed-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NSZ %s
14+
15+
! RUN: %flang -fno-associative-math -fno-signed-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NSZ %s
16+
! RUN: %flang -fno-associative-math -fsigned-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
17+
! RUN: %flang -fassociative-math -fno-signed-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,REASSOC_NSZ %s
18+
! RUN: %flang -fassociative-math -fsigned-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
19+
20+
! RUN: %flang -Kieee -fassociative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,REASSOC_NSZ %s
21+
! RUN: %flang -Kieee -fno-associative-math %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
22+
! RUN: %flang -Kieee -fsigned-zeros %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
23+
! RUN: %flang -Kieee -fno-signed-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NSZ %s
24+
! RUN: %flang -ffast-math -fassociative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_RELAXED,REASSOC_NSZ %s
25+
! RUN: %flang -ffast-math -fno-associative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
26+
! RUN: %flang -ffast-math -fsigned-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
27+
! RUN: %flang -ffast-math -fno-signed-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_RELAXED,NO_REASSOC,NSZ %s
28+
! RUN: %flang -frelaxed-math -fassociative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,REASSOC_NSZ %s
29+
! RUN: %flang -frelaxed-math -fno-associative-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,RELAXED,NO_REASSOC,NO_NSZ %s
30+
! RUN: %flang -frelaxed-math -fsigned-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,RELAXED,NO_REASSOC,NO_NSZ %s
31+
! RUN: %flang -frelaxed-math -fno-signed-zeros %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_REASSOC,NSZ %s
32+
33+
! RUN: %flang -fassociative-math -Kieee %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
34+
! RUN: %flang -fno-associative-math -Kieee %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
35+
! RUN: %flang -fsigned-zeros -Kieee %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
36+
! RUN: %flang -fno-signed-zeros -Kieee %s -### 2>&1 | FileCheck --check-prefixes=IEEE,NO_FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
37+
! RUN: %flang -fassociative-math -ffast-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_RELAXED,REASSOC_NSZ %s
38+
! RUN: %flang -fno-associative-math -ffast-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
39+
! RUN: %flang -fsigned-zeros -ffast-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,FAST,NO_RELAXED,NO_REASSOC,NO_NSZ %s
40+
! RUN: %flang -fno-signed-zeros -ffast-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_RELAXED,NO_REASSOC,NSZ %s
41+
! RUN: %flang -fassociative-math -frelaxed-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,REASSOC_NSZ %s
42+
! RUN: %flang -fno-associative-math -frelaxed-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,RELAXED,NO_REASSOC,NO_NSZ %s
43+
! RUN: %flang -fsigned-zeros -frelaxed-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,RELAXED,NO_REASSOC,NO_NSZ %s
44+
! RUN: %flang -fno-signed-zeros -frelaxed-math %s -### 2>&1 | FileCheck --check-prefixes=NO_IEEE,NO_FAST,NO_REASSOC,NSZ %s
45+
46+
! IEEE: {{.*}}flang2{{.*}} "-ieee" "1"
47+
! NO_IEEE-NOT: {{.*}}flang2{{.*}} "-ieee" "1"
48+
49+
! FAST: {{.*}}flang2{{.*}} "-x" "216" "1"
50+
! NO_FAST-NOT: {{.*}}flang2{{.*}} "-x" "216" "1"
51+
52+
! RELAXED: {{.*}}flang2{{.*}} "-x" "15" "0x400"
53+
! NO_RELAXED-NOT: {{.*}}flang2{{.*}} "-x" "15" "0x400"
54+
55+
! REASSOC_NSZ: {{.*}}flang2{{.*}} "-x" "216" "0x8" "-x" "216" "0x10"
56+
! NO_REASSOC-NOT: {{.*}}flang2{{.*}} "-x" "216" "0x10"
57+
58+
! NSZ: {{.*}}flang2{{.*}} "-x" "216" "0x8"
59+
! NO_NSZ-NOT: {{.*}}flang2{{.*}} "-x" "216" "0x8"

0 commit comments

Comments
 (0)