From 71698285e8c09654b801804466b33feb6db8645d Mon Sep 17 00:00:00 2001 From: Robert Bocchino Date: Tue, 27 Jul 2004 21:02:21 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15291 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 3c46e2c554b..8a797bfe222 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -509,8 +509,9 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { } // 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 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { 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(Op1); + } else if (ConstantFP *Op1F = dyn_cast(Op1)) { if (Op1F->isNullValue()) return ReplaceInstUsesWith(I, Op1); -- 2.34.1