Fixed the lost FastMathFlags for FCmp operations in SLPVectorizer.

Reviewer: Michael Zolotukhin.
Differential Revision: https://reviews.llvm.org/D26543

llvm-svn: 286626
This commit is contained in:
Vyacheslav Klochkov 2016-11-11 19:55:29 +00:00
parent 8ade03463e
commit f1a12fe0f5
2 changed files with 56 additions and 3 deletions

View File

@ -211,12 +211,12 @@ static unsigned getSameOpcode(ArrayRef<Value *> 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<Value *> VL) {
if (auto *VecOp = dyn_cast<BinaryOperator>(I)) {
if (auto *Intersection = dyn_cast<BinaryOperator>(VL[0])) {
if (auto *VecOp = dyn_cast<Instruction>(I)) {
if (auto *Intersection = dyn_cast<Instruction>(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<BinaryOperator>(VL[i]))
if (auto *Scalar = dyn_cast<Instruction>(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;
}

View File

@ -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" }