Fix a crash in InstCombine where we could try to truncate a switch comparison to...
authorOwen Anderson <resistor@mac.com>
Tue, 10 Mar 2015 06:51:39 +0000 (06:51 +0000)
committerOwen Anderson <resistor@mac.com>
Tue, 10 Mar 2015 06:51:39 +0000 (06:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231761 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/switch-truncate-crash.ll [new file with mode: 0644]

index 9e8b5774517eb0dcb7f438812a9a6c3079d3f29c..1fe036b5fbb42dbd5e55e0ca2e6a0ea117cb4a24 100644 (file)
@@ -2060,7 +2060,8 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) {
   // x86 generates redundant zero-extenstion instructions if the operand is
   // truncated to i8 or i16.
   bool TruncCond = false;
-  if (BitWidth > NewWidth && NewWidth >= DL.getLargestLegalIntTypeSize()) {
+  if (NewWidth > 0 && BitWidth > NewWidth &&
+      NewWidth >= DL.getLargestLegalIntTypeSize()) {
     TruncCond = true;
     IntegerType *Ty = IntegerType::get(SI.getContext(), NewWidth);
     Builder->SetInsertPoint(&SI);
diff --git a/test/Transforms/InstCombine/switch-truncate-crash.ll b/test/Transforms/InstCombine/switch-truncate-crash.ll
new file mode 100644 (file)
index 0000000..cc3c1ff
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: opt -instcombine < %s
+
+define void @test() {
+  switch i32 0, label %out [i32 0, label %out]
+out:
+  ret void
+}