[llvm] r299838 - [InstCombine] Make sure we preserve fast math flags when folding fp instructions into phi nodes
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 00:00:11 PDT 2017
Author: ctopper
Date: Mon Apr 10 02:00:10 2017
New Revision: 299838
URL: http://llvm.org/viewvc/llvm-project?rev=299838&view=rev
Log:
[InstCombine] Make sure we preserve fast math flags when folding fp instructions into phi nodes
Summary: I noticed in the select folding code that we copied fast math flags, but did not do the same for the similar handling in phi nodes. This patch fixes that to do the same thing as select
Reviewers: spatel, davide, majnemer, hfinkel
Reviewed By: davide
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D31690
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/fast-math.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=299838&r1=299837&r2=299838&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Mon Apr 10 02:00:10 2017
@@ -937,11 +937,15 @@ Instruction *InstCombiner::FoldOpIntoPhi
Constant *C = cast<Constant>(I.getOperand(1));
for (unsigned i = 0; i != NumPHIValues; ++i) {
Value *InV = nullptr;
- if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i)))
+ if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i))) {
InV = ConstantExpr::get(I.getOpcode(), InC, C);
- else
+ } else {
InV = Builder->CreateBinOp(cast<BinaryOperator>(I).getOpcode(),
PN->getIncomingValue(i), C, "phitmp");
+ auto *FPInst = dyn_cast<Instruction>(InV);
+ if (FPInst && isa<FPMathOperator>(FPInst))
+ FPInst->copyFastMathFlags(&I);
+ }
NewPN->addIncoming(InV, PN->getIncomingBlock(i));
}
} else {
Modified: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fast-math.ll?rev=299838&r1=299837&r2=299838&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll Mon Apr 10 02:00:10 2017
@@ -831,3 +831,26 @@ define fp128 @min4(fp128 %a, fp128 %b) {
; CHECK-NEXT: select {{.*}} fp128 %a, fp128 %b
; CHECK-NEXT: ret
}
+
+define float @test55(i1 %which, float %a) {
+; CHECK-LABEL: @test55(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
+; CHECK: delay:
+; CHECK-NEXT: [[PHITMP:%.*]] = fadd fast float [[A:%.*]], 1.000000e+00
+; CHECK-NEXT: br label [[FINAL]]
+; CHECK: final:
+; CHECK-NEXT: [[A:%.*]] = phi float [ 3.000000e+00, [[ENTRY:%.*]] ], [ [[PHITMP]], [[DELAY]] ]
+; CHECK-NEXT: ret float [[A]]
+;
+entry:
+ br i1 %which, label %final, label %delay
+
+delay:
+ br label %final
+
+final:
+ %A = phi float [ 2.0, %entry ], [ %a, %delay ]
+ %value = fadd fast float %A, 1.0
+ ret float %value
+}
More information about the llvm-commits
mailing list