Revert "[InstCombine] Fix visitSwitchInst to use right operand types for sub cstexpr"
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Fri, 19 Dec 2014 14:36:24 +0000 (14:36 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Fri, 19 Dec 2014 14:36:24 +0000 (14:36 +0000)
Reverts commit r224574 to appease buildbots:

The visitSwitchInst generates SUB constant expressions to recompute the
switch condition. When truncating the condition to a smaller type, SUB
expressions should use the previous type (before trunc) for both
operands. This fixes an assertion crash.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224576 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/narrow-switch.ll

index fc965b879dfdc844f8eed12f02d9b8ab1ab35085..5eee15f648906cc4997e03a8aaf7ea002cf50063 100644 (file)
@@ -2115,10 +2115,8 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) {
         for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end();
              i != e; ++i) {
           ConstantInt* CaseVal = i.getCaseValue();
-          Constant *LHS = LeadingKnownZeros
-                              ? ConstantExpr::getZExt(CaseVal, Cond->getType())
-                              : ConstantExpr::getSExt(CaseVal, Cond->getType());
-          Constant* NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
+          Constant* NewCaseVal = ConstantExpr::getSub(cast<Constant>(CaseVal),
+                                                      AddRHS);
           assert(isa<ConstantInt>(NewCaseVal) &&
                  "Result of expression should be constant");
           i.setValue(cast<ConstantInt>(NewCaseVal));
index f3f19bae03dda75e7118b5bc3e88628fde68f939..7646189b8540f93102c48e57457857ed359f757c 100644 (file)
@@ -91,33 +91,3 @@ return:
   %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
   ret i32 %retval.0
 }
-
-; Make sure to avoid assertion crashes and use the type before
-; truncation to generate the sub constant expressions that leads
-; to the recomputed condition.
-;
-; CHECK-LABEL: @trunc64to59
-; CHECK: switch i59
-; CHECK: i59 0, label
-; CHECK: i59 18717182647723699, label
-
-define void @trunc64to59(i64 %a) {
-entry:
-  %tmp0 = and i64 %a, 15
-  %tmp1 = mul i64 %tmp0, -6425668444178048401
-  %tmp2 = add i64 %tmp1, 5170979678563097242
-  %tmp3 = mul i64 %tmp2, 1627972535142754813
-  switch i64 %tmp3, label %sw.default [
-    i64 847514119312061490, label %sw.bb1
-    i64 866231301959785189, label %sw.bb2
-  ]
-
-sw.bb1:
-  br label %sw.default
-
-sw.bb2:
-  br label %sw.default
-
-sw.default:
-  ret void
-}