[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Robert Bocchino bocchino at cs.uiuc.edu
Tue Jul 27 14:02:32 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.232 -> 1.233

---
Log message:



This change fixed a bug in the function visitMul.  The prior version
assumed that a constant on the RHS of a multiplication was either an
IntConstant or an FPConstant.  It checked for an IntConstant and then,
if it did not find one, did a hard cast to an FPConstant.  That code
would crash if the RHS were a ConstantExpr that was neither an
IntConstant nor an FPConstant.  This version replaces the hard cast
with a dyn_cast.  It performs the same way for IntConstants and
FPConstants but does nothing, instead of crashing, for constant
expressions.

The regression test for this change is 2004-07-27-ConstantExprMul.ll.


---
Diffs of the changes:  (+3 -3)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.232 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.233
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.232	Tue Jul 27 12:43:21 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Tue Jul 27 16:02:21 2004
@@ -509,8 +509,9 @@
   }
 
   // X + X --> X << 1
-  if (I.getType()->isInteger())
+  if (I.getType()->isInteger()) {
     if (Instruction *Result = AssociativeOpt(I, AddRHS(RHS))) return Result;
+  }
 
   // -A + B  -->  B - A
   if (Value *V = dyn_castNegVal(LHS))
@@ -745,8 +746,7 @@
       if (uint64_t C = Log2(Val))            // Replace X*(2^C) with X << C
         return new ShiftInst(Instruction::Shl, Op0,
                              ConstantUInt::get(Type::UByteTy, C));
-    } else {
-      ConstantFP *Op1F = cast<ConstantFP>(Op1);
+    } else if (ConstantFP *Op1F = dyn_cast<ConstantFP>(Op1)) {
       if (Op1F->isNullValue())
         return ReplaceInstUsesWith(I, Op1);
 





More information about the llvm-commits mailing list