InstCombine: Fix another infinite loop caused by visitFPTrunc
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombineCasts.cpp
index a0570f7ebd474d5d61b4afcc1a7f7598dec8465d..aba77bb44625cb67c1afa7683571d3b447c8b16f 100644 (file)
@@ -1269,13 +1269,12 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
         // 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());