[llvm] r222265 - InstCombine: Fix another infinite loop caused by visitFPTrunc
David Majnemer
david.majnemer at gmail.com
Tue Nov 18 14:06:46 PST 2014
Author: majnemer
Date: Tue Nov 18 16:06:45 2014
New Revision: 222265
URL: http://llvm.org/viewvc/llvm-project?rev=222265&view=rev
Log:
InstCombine: Fix another infinite loop caused by visitFPTrunc
We would attempt to replace an frem's operand with the same operand.
This would cause InstCombine to think real work was done, causing
InstCombine to enter an infinite loop.
This fixes the second part of PR21576.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/trunk/test/Transforms/InstCombine/fpcast.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=222265&r1=222264&r2=222265&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Tue Nov 18 16:06:45 2014
@@ -1269,13 +1269,12 @@ Instruction *InstCombiner::visitFPTrunc(
// type of OpI doesn't enter into things at all. We simply evaluate
// in whichever source type is larger, then convert to the
// destination type.
- Value *NewLHS = LHSOrig, *NewRHS = RHSOrig;
if (LHSWidth < SrcWidth)
- NewLHS = Builder->CreateFPExt(NewLHS, RHSOrig->getType());
+ LHSOrig = Builder->CreateFPExt(LHSOrig, RHSOrig->getType());
else if (RHSWidth <= SrcWidth)
- NewRHS = Builder->CreateFPExt(NewRHS, LHSOrig->getType());
- if (NewLHS != LHSOrig || NewRHS != RHSOrig) {
- Value *ExactResult = Builder->CreateFRem(NewLHS, NewRHS);
+ RHSOrig = Builder->CreateFPExt(RHSOrig, LHSOrig->getType());
+ if (LHSOrig != OpI->getOperand(0) || RHSOrig != OpI->getOperand(1)) {
+ Value *ExactResult = Builder->CreateFRem(LHSOrig, RHSOrig);
if (Instruction *RI = dyn_cast<Instruction>(ExactResult))
RI->copyFastMathFlags(OpI);
return CastInst::CreateFPCast(ExactResult, CI.getType());
Modified: llvm/trunk/test/Transforms/InstCombine/fpcast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fpcast.ll?rev=222265&r1=222264&r2=222265&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fpcast.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fpcast.ll Tue Nov 18 16:06:45 2014
@@ -63,3 +63,13 @@ define <1 x float> @test6(<1 x double> %
; CHECK-NEXT: %[[trunc:.*]] = fptrunc <1 x double> %[[frem]] to <1 x float>
; CHECK-NEXT: ret <1 x float> %trunc
}
+
+define float @test7(double %V) {
+ %frem = frem double %V, 1.000000e+00
+ %trunc = fptrunc double %frem to float
+ ret float %trunc
+; CHECK-LABEL: @test7
+; CHECK-NEXT: %[[frem:.*]] = frem double %V, 1.000000e+00
+; CHECK-NEXT: %[[trunc:.*]] = fptrunc double %frem to float
+; CHECK-NEXT: ret float %trunc
+}
More information about the llvm-commits
mailing list