[PATCH] [InstCombine] Fix visitSwitchInst to use right operand types for sub cstexpr.
David Majnemer
david.majnemer at gmail.com
Mon Dec 15 13:48:28 PST 2014
================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2122
@@ +2121,3 @@
+ TruncCond ? ConstantInt::get(SI.getContext(),
+ CaseVal->getValue().sext(BitWidth))
+ : CaseVal);
----------------
bruno wrote:
> majnemer wrote:
> > Is there any particular reason why you chose to sext instead of zext?
> Being conservative to perform the right extension when coming back from the truncated negative condition cases. Would that be somehow redundant in this scenario?
I don't think it will actually be faster.
`ConstantExpr::getSExt(CaseVal, Cond->getType())` will call `getFoldedCast` which will call `ConstantFoldCastInstruction` which will do the following:
case Instruction::SExt:
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
return ConstantInt::get(V->getContext(),
CI->getValue().sext(BitWidth));
}
Seems like it will do the exact same thing. No table lookups involved.
http://reviews.llvm.org/D6644
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list