diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 48a747d764af..601d9b42f314 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -29,10 +29,6 @@ static Value *DecomposeSimpleLinearExpr(Value *Val, unsigned &Scale, return ConstantInt::get(Val->getType(), 0); } - // Insist that the amount-to-allocate not overflow. - OverflowingBinaryOperator *OBI = dyn_cast(Val); - if (OBI && !OBI->hasNoUnsignedWrap()) return 0; - if (BinaryOperator *I = dyn_cast(Val)) { if (ConstantInt *RHS = dyn_cast(I->getOperand(1))) { if (I->getOpcode() == Instruction::Shl) { @@ -75,6 +71,11 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI, // This requires TargetData to get the alloca alignment and size information. if (!TD) return 0; + // Insist that the amount-to-allocate not overflow. + OverflowingBinaryOperator *OBI = + dyn_cast(AI.getOperand(0)); + if (OBI && !(OBI->hasNoSignedWrap() || OBI->hasNoUnsignedWrap())) return 0; + const PointerType *PTy = cast(CI.getType()); BuilderTy AllocaBuilder(*Builder);