summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-11-24 07:26:20 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-11-24 07:26:20 +0000
commitb2a6e7458d7229d53e59824d0a350b1a054f165a (patch)
treeafb3884fe93640b970d5194a80c6531e4a6d6375 /llvm
parent403011848502577344a222633918496fa03f32d4 (diff)
downloadbcm5719-llvm-b2a6e7458d7229d53e59824d0a350b1a054f165a.tar.gz
bcm5719-llvm-b2a6e7458d7229d53e59824d0a350b1a054f165a.zip
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. llvm-svn: 222645
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp3
-rw-r--r--llvm/test/Transforms/InstCombine/pr21651.ll20
2 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 292c20678ec..5eee15f6489 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2095,7 +2095,8 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) {
// 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");
diff --git a/llvm/test/Transforms/InstCombine/pr21651.ll b/llvm/test/Transforms/InstCombine/pr21651.ll
new file mode 100644
index 00000000000..914785f329a
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/pr21651.ll
@@ -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: }
OpenPOWER on IntegriCloud