Index: lib/IR/ConstantFold.cpp =================================================================== --- lib/IR/ConstantFold.cpp +++ lib/IR/ConstantFold.cpp @@ -1120,27 +1120,18 @@ return ConstantInt::get(CI1->getContext(), C1V | C2V); case Instruction::Xor: return ConstantInt::get(CI1->getContext(), C1V ^ C2V); - case Instruction::Shl: { - uint32_t shiftAmt = C2V.getZExtValue(); - if (shiftAmt < C1V.getBitWidth()) - return ConstantInt::get(CI1->getContext(), C1V.shl(shiftAmt)); - else + case Instruction::Shl: + if (C2V.getActiveBits() > 32 || C2V.getZExtValue() >= C1V.getBitWidth()) return UndefValue::get(C1->getType()); // too big shift is undef - } - case Instruction::LShr: { - uint32_t shiftAmt = C2V.getZExtValue(); - if (shiftAmt < C1V.getBitWidth()) - return ConstantInt::get(CI1->getContext(), C1V.lshr(shiftAmt)); - else + return ConstantInt::get(CI1->getContext(), C1V.shl(C2V.getZExtValue())); + case Instruction::LShr: + if (C2V.getActiveBits() > 32 || C2V.getZExtValue() >= C1V.getBitWidth()) return UndefValue::get(C1->getType()); // too big shift is undef - } - case Instruction::AShr: { - uint32_t shiftAmt = C2V.getZExtValue(); - if (shiftAmt < C1V.getBitWidth()) - return ConstantInt::get(CI1->getContext(), C1V.ashr(shiftAmt)); - else + return ConstantInt::get(CI1->getContext(), C1V.lshr(C2V.getZExtValue())); + case Instruction::AShr: + if (C2V.getActiveBits() > 32 || C2V.getZExtValue() >= C1V.getBitWidth()) return UndefValue::get(C1->getType()); // too big shift is undef - } + return ConstantInt::get(CI1->getContext(), C1V.ashr(C2V.getZExtValue())); } }