diff options
author | Serge Guelton <sguelton@quarkslab.com> | 2017-07-10 16:51:40 +0000 |
---|---|---|
committer | Serge Guelton <sguelton@quarkslab.com> | 2017-07-10 16:51:40 +0000 |
commit | f6329ec2e9b695263ec665bb2a482169c6f89d96 (patch) | |
tree | b9e8127f7e87435148be9c539e82baebc7f7d9d0 /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 168d14b143d04466984db81d50e6e5db8cb5d5bd (diff) | |
download | bcm5719-llvm-f6329ec2e9b695263ec665bb2a482169c6f89d96.tar.gz bcm5719-llvm-f6329ec2e9b695263ec665bb2a482169c6f89d96.zip |
Fix invalid cast in instcombine UMul/ZExt idiom
Fixes https://bugs.llvm.org/show_bug.cgi?id=25454
Do not assume IRBuilder creates Instruction where it can create Value.
Do not assume idiom operands are constant, leave generalisation ot the IRBuilder.
Differential Revision: https://reviews.llvm.org/D35114
llvm-svn: 307554
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4dae49108ec..60d1cde971d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3856,17 +3856,18 @@ static Instruction *processUMulZExtIdiom(ICmpInst &I, Value *MulVal, } else if (BinaryOperator *BO = dyn_cast<BinaryOperator>(U)) { assert(BO->getOpcode() == Instruction::And); // Replace (mul & mask) --> zext (mul.with.overflow & short_mask) - ConstantInt *CI = cast<ConstantInt>(BO->getOperand(1)); - APInt ShortMask = CI->getValue().trunc(MulWidth); + Value *ShortMask = + Builder.CreateTrunc(BO->getOperand(1), Builder.getIntNTy(MulWidth)); Value *ShortAnd = Builder.CreateAnd(Mul, ShortMask); - Instruction *Zext = - cast<Instruction>(Builder.CreateZExt(ShortAnd, BO->getType())); - IC.Worklist.Add(Zext); + Value *Zext = Builder.CreateZExt(ShortAnd, BO->getType()); + if (auto *ZextI = dyn_cast<Instruction>(Zext)) + IC.Worklist.Add(ZextI); IC.replaceInstUsesWith(*BO, Zext); } else { llvm_unreachable("Unexpected Binary operation"); } - IC.Worklist.Add(cast<Instruction>(U)); + if (auto *UI = dyn_cast<Instruction>(U)) + IC.Worklist.Add(UI); } } if (isa<Instruction>(OtherVal)) |