Port enabling of loop vectorization and fast math from mainline.
llvm-svn: 182833
diff --git a/dragonegg/src/Backend.cpp b/dragonegg/src/Backend.cpp
index 7b040e2..ccd1140 100644
--- a/dragonegg/src/Backend.cpp
+++ b/dragonegg/src/Backend.cpp
@@ -643,12 +643,11 @@
// Configure the pass builder.
PassBuilder.SizeLevel = optimize_size;
PassBuilder.DisableSimplifyLibCalls = flag_no_simplify_libcalls;
- PassBuilder.DisableUnrollLoops = !flag_unroll_loops;
PassBuilder.DisableUnitAtATime = !flag_unit_at_a_time;
- // FIXME: Hack around the fact the we initialize PassBuilder before processing
- // command line arguments. The following makes it possible to enable the LLVM
- // vectorizer using -fplugin-arg-dragonegg-llvm-option=-vectorize
- PassBuilder.SLPVectorize = PassManagerBuilder().SLPVectorize;
+ PassBuilder.DisableUnrollLoops = !flag_unroll_loops;
+// Don't turn on the SLP vectorizer by default at -O3 for the moment.
+// PassBuilder.SLPVectorize = flag_tree_slp_vectorize;
+ PassBuilder.LoopVectorize = flag_tree_vectorize;
PassBuilder.LibraryInfo =
new TargetLibraryInfo((Triple) TheModule->getTargetTriple());
diff --git a/dragonegg/src/Convert.cpp b/dragonegg/src/Convert.cpp
index 929e52a..d0be372 100644
--- a/dragonegg/src/Convert.cpp
+++ b/dragonegg/src/Convert.cpp
@@ -1639,6 +1639,19 @@
}
Function *TreeToLLVM::EmitFunction() {
+ FastMathFlags FMF;
+ if (flag_finite_math_only) {
+ FMF.setNoInfs();
+ FMF.setNoNaNs();
+ }
+ if (!flag_signed_zeros)
+ FMF.setNoSignedZeros();
+ if (flag_reciprocal_math)
+ FMF.setAllowReciprocal();
+ if (flag_unsafe_math_optimizations && flag_finite_math_only)
+ FMF.setUnsafeAlgebra();
+ Builder.SetFastMathFlags(FMF);
+
// Set up parameters and prepare for return, for the function.
StartFunctionBody();
diff --git a/dragonegg/test/compilator/compilator-lit.cfg b/dragonegg/test/compilator/compilator-lit.cfg
index 33cc642..6007b53 100644
--- a/dragonegg/test/compilator/compilator-lit.cfg
+++ b/dragonegg/test/compilator/compilator-lit.cfg
@@ -39,8 +39,8 @@
addMutuallyExclusiveFlags([None, '-O1', '-O2', '-O3'])
# The following are not mutually exclusive, but pretending they are speeds up
# testing. Doing this fails to catch tests that pass with -g and also with
-# -march=native but fail with -g -march=native. Do such tests even exist?
-addMutuallyExclusiveFlags([None, '-g', '-march=native'])
+# -march=native but fail with -g -march=native etc.
+addMutuallyExclusiveFlags([None, '-g', '-march=native', '-ffast-math'])
config.skip = [
'gcc-testsuite/g++.dg/eh/cleanup1.C', # PR11811
diff --git a/dragonegg/test/validator/c/fast-math.c b/dragonegg/test/validator/c/fast-math.c
new file mode 100644
index 0000000..60a7879
--- /dev/null
+++ b/dragonegg/test/validator/c/fast-math.c
@@ -0,0 +1,12 @@
+// RUN: %dragonegg -S %s -o - | FileCheck -check-prefix=DEFAULT %s
+// RUN: %dragonegg -S %s -o - -ffast-math | FileCheck -check-prefix=FASTMATH %s
+// RUN: %dragonegg -S %s -o - -ffinite-math-only | FileCheck -check-prefix=FINITEMATHONLY %s
+// RUN: %dragonegg -S %s -o - -fno-signed-zeros | FileCheck -check-prefix=NOSIGNEDZEROS %s
+
+double fm(double x, double y) {
+ return x+y;
+// DEFAULT: fadd double
+// FASTMATH: fadd fast
+// FINITEMATHONLY: fadd nnan ninf
+// NOSIGNEDZEROS: fadd nsz
+}
diff --git a/dragonegg/test/validator/c/vectorizer.c b/dragonegg/test/validator/c/vectorizer.c
new file mode 100644
index 0000000..ea64892
--- /dev/null
+++ b/dragonegg/test/validator/c/vectorizer.c
@@ -0,0 +1,10 @@
+// RUN: %dragonegg -S %s -o - -O3 | FileCheck -check-prefix=VON %s
+// RUN: %dragonegg -S %s -o - -O3 -fno-tree-vectorize | FileCheck -check-prefix=VOFF %s
+// VON: fadd <
+// VOFF-NOT: fadd <
+
+void bar(float *A, float* B, float K) {
+ int i;
+ for (i = 0; i < 64; ++i)
+ A[i] *= B[i] + K;
+}