[PATCH] [InstCombine] Fix visitSwitchInst to use right operand types for sub cstexpr.
Bruno Cardoso Lopes
bruno.cardoso at gmail.com
Tue Dec 16 04:16:52 PST 2014
================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2122
@@ +2121,3 @@
+ TruncCond ? ConstantInt::get(SI.getContext(),
+ CaseVal->getValue().sext(BitWidth))
+ : CaseVal);
----------------
majnemer wrote:
> 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.
-----------
As I said before, it takes additional calls for every case statement. We don't need to bikeshed on that though, I guess that won't make that much difference either.
http://reviews.llvm.org/D6644
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list