[PATCH] D31690: [InstCombine] Make sure we preserve fast math flags when folding fp instructions into phi nodes
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 11:07:35 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299838: [InstCombine] Make sure we preserve fast math flags when folding fp… (authored by ctopper).
Changed prior to commit:
https://reviews.llvm.org/D31690?vs=94146&id=94641#toc
Repository:
rL LLVM
https://reviews.llvm.org/D31690
Files:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/trunk/test/Transforms/InstCombine/fast-math.ll
Index: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/fast-math.ll
+++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll
@@ -831,3 +831,26 @@
; 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
+}
Index: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -937,11 +937,15 @@
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 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31690.94641.patch
Type: text/x-patch
Size: 2039 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170410/75dd9448/attachment.bin>
More information about the llvm-commits
mailing list