[PATCH] D17585: Fix failure of InstCombine to propagate fast math flags when scalarizing vector arithmetic.

Owen Anderson via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 16:09:19 PST 2016


resistor created this revision.
resistor added a reviewer: hfinkel.
resistor added a subscriber: llvm-commits.
resistor set the repository for this revision to rL LLVM.

Most portions of InstCombine properly propagate fast math flags, but apparently the vector secularization section was overlooked.

Repository:
  rL LLVM

http://reviews.llvm.org/D17585

Files:
  lib/Transforms/InstCombine/InstCombineVectorOps.cpp
  test/Transforms/InstCombine/fast-math-scalarization.ll

Index: test/Transforms/InstCombine/fast-math-scalarization.ll
===================================================================
--- /dev/null
+++ test/Transforms/InstCombine/fast-math-scalarization.ll
@@ -0,0 +1,39 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+; CHECK-LABEL: test_scalarize_phi
+; CHECK: fmul fast float
+define void @test_scalarize_phi(i32 * %n, float * %inout) {
+entry:
+  %0 = load volatile float, float * %inout, align 4
+  %splat.splatinsert = insertelement <4 x float> undef, float %0, i32 0
+  %splat.splat = shufflevector <4 x float> %splat.splatinsert, <4 x float> undef, <4 x i32> zeroinitializer
+  %splat.splatinsert1 = insertelement <4 x float> undef, float 3.0, i32 0
+  br label %for.cond
+
+for.cond:
+  %x.0 = phi <4 x float> [ %splat.splat, %entry ], [ %mul, %for.body ]
+  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+  %1 = load i32, i32 * %n, align 4
+  %cmp = icmp ne i32 %i.0, %1
+  br i1 %cmp, label %for.body, label %for.end
+
+for.body:
+  %2 = extractelement <4 x float> %x.0, i32 1
+  store volatile float %2, float * %inout, align 4
+  %mul = fmul fast <4 x float> %x.0, <float 0x4002A3D700000000, float 0x4002A3D700000000, float 0x4002A3D700000000, float 0x4002A3D700000000>
+  %inc = add nsw i32 %i.0, 1
+  br label %for.cond
+
+for.end:
+  ret void
+}
+
+; CHECK-LABEL: test_extract_element_fastmath
+; CHECK: fadd fast float
+define float @test_extract_element_fastmath(<4 x float> %x) #0 {
+entry:
+  %add = fadd fast <4 x float> %x, <float 0x4002A3D700000000, float 0x4002A3D700000000, float 0x4002A3D700000000, float 0x4002A3D700000000>
+  %0 = extractelement <4 x float> %add, i32 2
+  ret float %0
+}
+
Index: lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -105,8 +105,9 @@
           ExtractElementInst::Create(B0->getOperand(opId), Elt,
                                      B0->getOperand(opId)->getName() + ".Elt"),
           *B0);
-      Value *newPHIUser = InsertNewInstWith(
-          BinaryOperator::Create(B0->getOpcode(), scalarPHI, Op), *B0);
+      BinaryOperator *newPHIUser = cast<BinaryOperator>(InsertNewInstWith(
+          BinaryOperator::Create(B0->getOpcode(), scalarPHI, Op), *B0));
+      newPHIUser->copyIRFlags(B0);
       scalarPHI->addIncoming(newPHIUser, inBB);
     } else {
       // Scalarize PHI input:
@@ -194,7 +195,10 @@
         Value *newEI1 =
           Builder->CreateExtractElement(BO->getOperand(1), EI.getOperand(1),
                                         EI.getName()+".rhs");
-        return BinaryOperator::Create(BO->getOpcode(), newEI0, newEI1);
+        BinaryOperator *NewBO =
+          BinaryOperator::Create(BO->getOpcode(), newEI0, newEI1);
+        NewBO->copyIRFlags(BO);
+        return NewBO;
       }
     } else if (InsertElementInst *IE = dyn_cast<InsertElementInst>(I)) {
       // Extracting the inserted element?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17585.48988.patch
Type: text/x-patch
Size: 3039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160225/174eaaad/attachment.bin>


More information about the llvm-commits mailing list