diff options
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/switch-truncate-crash.ll | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 9e8b5774517..1fe036b5fbb 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -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/llvm/test/Transforms/InstCombine/switch-truncate-crash.ll b/llvm/test/Transforms/InstCombine/switch-truncate-crash.ll new file mode 100644 index 00000000000..cc3c1ff28ed --- /dev/null +++ b/llvm/test/Transforms/InstCombine/switch-truncate-crash.ll @@ -0,0 +1,7 @@ +; RUN: opt -instcombine < %s + +define void @test() { + switch i32 0, label %out [i32 0, label %out] +out: + ret void +} |