[PATCH] [InstCombine] Fix visitSwitchInst to use right operand types for sub cstexpr.

David Majnemer david.majnemer at gmail.com
Sun Dec 14 02:44:37 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;
----------------
InstCombine methods are supposed to return the original instruction if they modify the instruction.  It seems `visitSwitchInst` isn't doing this here.

================
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);
----------------
Isn't this equivalent to:
`Constant *LHS = ConstantExpr::getSExt(CaseVal, BitWidth);`

================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2124
@@ -2120,1 +2123,3 @@
+                        : CaseVal);
+          Constant* NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
           assert(isa<ConstantInt>(NewCaseVal) &&
----------------
Might as well make this `Constant *` since you are changing the right hand side.

================
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:
> 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.

http://reviews.llvm.org/D6644

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list