From: Vyacheslav Klochkov Date: Fri, 11 Nov 2016 19:55:29 +0000 (+0000) Subject: Fixed the lost FastMathFlags for FCmp operations in SLPVectorizer. X-Git-Tag: llvmorg-4.0.0-rc1~4871 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f1a12fe0f5de5e07937b8cb99ceda2487713f7c8;p=platform%2Fupstream%2Fllvm.git Fixed the lost FastMathFlags for FCmp operations in SLPVectorizer. Reviewer: Michael Zolotukhin. Differential Revision: https://reviews.llvm.org/D26543 llvm-svn: 286626 --- diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 73dca75..6b27ac6 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -211,12 +211,12 @@ static unsigned getSameOpcode(ArrayRef VL) { /// of each scalar operation (VL) that will be converted into a vector (I). /// Flag set: NSW, NUW, exact, and all of fast-math. static void propagateIRFlags(Value *I, ArrayRef VL) { - if (auto *VecOp = dyn_cast(I)) { - if (auto *Intersection = dyn_cast(VL[0])) { + if (auto *VecOp = dyn_cast(I)) { + if (auto *Intersection = dyn_cast(VL[0])) { // Intersection is initialized to the 0th scalar, // so start counting from index '1'. for (int i = 1, e = VL.size(); i < e; ++i) { - if (auto *Scalar = dyn_cast(VL[i])) + if (auto *Scalar = dyn_cast(VL[i])) Intersection->andIRFlags(Scalar); } VecOp->copyIRFlags(Intersection); @@ -2430,6 +2430,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { V = Builder.CreateICmp(P0, L, R); E->VectorizedValue = V; + propagateIRFlags(E->VectorizedValue, E->Scalars); ++NumVectorInstructions; return V; } diff --git a/llvm/test/Transforms/SLPVectorizer/X86/propagate_ir_flags.ll b/llvm/test/Transforms/SLPVectorizer/X86/propagate_ir_flags.ll index a3b0c8f..3f26c81 100644 --- a/llvm/test/Transforms/SLPVectorizer/X86/propagate_ir_flags.ll +++ b/llvm/test/Transforms/SLPVectorizer/X86/propagate_ir_flags.ll @@ -348,3 +348,55 @@ define void @addsub_no_nsw(i32* %x) { ret void } +; CHECK-LABEL: @fcmp_fast +; CHECK: fcmp fast oge <2 x double> +; CHECK: sub fast <2 x double> +define void @fcmp_fast(double* %x) #1 { + %idx1 = getelementptr inbounds double, double* %x, i64 0 + %idx2 = getelementptr inbounds double, double* %x, i64 1 + + %load1 = load double, double* %idx1, align 8 + %load2 = load double, double* %idx2, align 8 + + %cmp1 = fcmp fast oge double %load1, 0.000000e+00 + %cmp2 = fcmp fast oge double %load2, 0.000000e+00 + + %sub1 = fsub fast double -0.000000e+00, %load1 + %sub2 = fsub fast double -0.000000e+00, %load2 + + %sel1 = select i1 %cmp1, double %load1, double %sub1 + %sel2 = select i1 %cmp2, double %load2, double %sub2 + + store double %sel1, double* %idx1, align 8 + store double %sel2, double* %idx2, align 8 + + ret void +} + +; CHECK-LABEL: @fcmp_no_fast +; CHECK: fcmp oge <2 x double> +; CHECK: sub <2 x double> +define void @fcmp_no_fast(double* %x) #1 { + %idx1 = getelementptr inbounds double, double* %x, i64 0 + %idx2 = getelementptr inbounds double, double* %x, i64 1 + + %load1 = load double, double* %idx1, align 8 + %load2 = load double, double* %idx2, align 8 + + %cmp1 = fcmp fast oge double %load1, 0.000000e+00 + %cmp2 = fcmp oge double %load2, 0.000000e+00 + + %sub1 = fsub fast double -0.000000e+00, %load1 + %sub2 = fsub double -0.000000e+00, %load2 + + %sel1 = select i1 %cmp1, double %load1, double %sub1 + %sel2 = select i1 %cmp2, double %load2, double %sub2 + + store double %sel1, double* %idx1, align 8 + store double %sel2, double* %idx2, align 8 + + ret void +} + +attributes #1 = { "target-features"="+avx" } +