[PATCH] [InstCombine] Fix visitSwitchInst to use right operand types for sub cstexpr.
Bruno Cardoso Lopes
bruno.cardoso at gmail.com
Mon Dec 15 09:51:25 PST 2014
REPOSITORY
rL LLVM
================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2107-2108
@@ -2105,3 +2106,4 @@
for (auto &C : SI.cases())
static_cast<SwitchInst::CaseIt *>(&C)->setValue(ConstantInt::get(
SI.getContext(), C.getCaseValue()->getValue().trunc(NewWidth)));
+ TruncCond = true;
----------------
majnemer wrote:
> InstCombine methods are supposed to return the original instruction if they modify the instruction. It seems `visitSwitchInst` isn't doing this here.
Good catch, in case where Trunc instruction is generated but no ADD instruction is found we're returning null. Will address that in a next patch since this is not related to this fix.
================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2120-2123
@@ -2117,3 +2119,6 @@
ConstantInt* CaseVal = i.getCaseValue();
- Constant* NewCaseVal = ConstantExpr::getSub(cast<Constant>(CaseVal),
- AddRHS);
+ Constant *LHS = cast<Constant>(
+ TruncCond ? ConstantInt::get(SI.getContext(),
+ CaseVal->getValue().sext(BitWidth))
+ : CaseVal);
+ Constant* NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
----------------
majnemer wrote:
> Isn't this equivalent to:
> `Constant *LHS = ConstantExpr::getSExt(CaseVal, BitWidth);`
Likely, but only after a series of constant fold lookups/calls for the common cases, I guess the current version is uglier but faster.
================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2124
@@ -2120,1 +2123,3 @@
+ : CaseVal);
+ Constant* NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
assert(isa<ConstantInt>(NewCaseVal) &&
----------------
majnemer wrote:
> majnemer wrote:
> > Might as well make this `Constant *` since you are changing the right hand side.
> Might as well put the pointer on the right hand side.
Ok!
http://reviews.llvm.org/D6644
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list