[llvm] r222645 - InstCombine: Don't assume DataLayout is always available
David Majnemer
david.majnemer at gmail.com
Sun Nov 23 23:26:21 PST 2014
Author: majnemer
Date: Mon Nov 24 01:26:20 2014
New Revision: 222645
URL: http://llvm.org/viewvc/llvm-project?rev=222645&view=rev
Log:
InstCombine: Don't assume DataLayout is always available
We tried to get the result of DataLayout::getLargestLegalIntTypeSize but
we didn't have a DataLayout. This resulted in opt crashing.
This fixes PR21651.
Added:
llvm/trunk/test/Transforms/InstCombine/pr21651.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=222645&r1=222644&r2=222645&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Mon Nov 24 01:26:20 2014
@@ -2095,7 +2095,8 @@ Instruction *InstCombiner::visitSwitchIn
// the largest legal integer type. We need to be conservative here since
// x86 generates redundant zero-extenstion instructions if the operand is
// truncated to i8 or i16.
- if (BitWidth > NewWidth && NewWidth >= DL->getLargestLegalIntTypeSize()) {
+ if (DL && BitWidth > NewWidth &&
+ NewWidth >= DL->getLargestLegalIntTypeSize()) {
IntegerType *Ty = IntegerType::get(SI.getContext(), NewWidth);
Builder->SetInsertPoint(&SI);
Value *NewCond = Builder->CreateTrunc(SI.getCondition(), Ty, "trunc");
Added: llvm/trunk/test/Transforms/InstCombine/pr21651.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/pr21651.ll?rev=222645&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/pr21651.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/pr21651.ll Mon Nov 24 01:26:20 2014
@@ -0,0 +1,20 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define void @PR21651() {
+ switch i2 0, label %out [
+ i2 0, label %out
+ i2 1, label %out
+ ]
+
+out:
+ ret void
+}
+
+; CHECK-LABEL: define void @PR21651(
+; CHECK: switch i2 0, label %out [
+; CHECK: i2 0, label %out
+; CHECK: i2 1, label %out
+; CHECK: ]
+; CHECK: out: ; preds = %0, %0, %0
+; CHECK: ret void
+; CHECK: }
More information about the llvm-commits
mailing list