[llvm] r231761 - Fix a crash in InstCombine where we could try to truncate a switch comparison to zero width.

Owen Anderson resistor at mac.com
Mon Mar 9 23:51:39 PDT 2015


Author: resistor
Date: Tue Mar 10 01:51:39 2015
New Revision: 231761

URL: http://llvm.org/viewvc/llvm-project?rev=231761&view=rev
Log:
Fix a crash in InstCombine where we could try to truncate a switch comparison to zero width.

Added:
    llvm/trunk/test/Transforms/InstCombine/switch-truncate-crash.ll
Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=231761&r1=231760&r2=231761&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Tue Mar 10 01:51:39 2015
@@ -2060,7 +2060,8 @@ Instruction *InstCombiner::visitSwitchIn
   // 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);

Added: llvm/trunk/test/Transforms/InstCombine/switch-truncate-crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/switch-truncate-crash.ll?rev=231761&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/switch-truncate-crash.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/switch-truncate-crash.ll Tue Mar 10 01:51:39 2015
@@ -0,0 +1,7 @@
+; RUN: opt -instcombine < %s
+
+define void @test() {
+  switch i32 0, label %out [i32 0, label %out]
+out:
+  ret void
+}





More information about the llvm-commits mailing list