summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp8
-rw-r--r--llvm/test/Transforms/InstCombine/bitcast-store.ll15
-rw-r--r--llvm/test/Transforms/InstCombine/load.ll18
3 files changed, 41 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 16032780142..8295899251a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -465,6 +465,10 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
if (LI.use_empty())
return nullptr;
+ // swifterror values can't be bitcasted.
+ if (LI.getPointerOperand()->isSwiftError())
+ return nullptr;
+
Type *Ty = LI.getType();
const DataLayout &DL = IC.getDataLayout();
@@ -997,6 +1001,10 @@ static bool combineStoreToValueType(InstCombiner &IC, StoreInst &SI) {
if (!SI.isUnordered())
return false;
+ // swifterror values can't be bitcasted.
+ if (SI.getPointerOperand()->isSwiftError())
+ return false;
+
Value *V = SI.getValueOperand();
// Fold away bit casts of the stored value by storing the original type.
diff --git a/llvm/test/Transforms/InstCombine/bitcast-store.ll b/llvm/test/Transforms/InstCombine/bitcast-store.ll
index ea4d680ade5..6d795271755 100644
--- a/llvm/test/Transforms/InstCombine/bitcast-store.ll
+++ b/llvm/test/Transforms/InstCombine/bitcast-store.ll
@@ -32,4 +32,19 @@ entry:
ret void
}
+; Check that we don't combine the bitcast into the store. This would create a
+; bitcast of the swifterror which is invalid.
+
+; CHECK-LABEL; @swifterror_store
+; CHECK: bitcast i64
+; CHECK: store %swift.error
+
+%swift.error = type opaque
+define void @swifterror_store(i64* %x, %swift.error** swifterror %err) {
+entry:
+ %casted = bitcast i64* %x to %swift.error*
+ store %swift.error* %casted, %swift.error** %err
+ ret void
+}
+
!0 = !{!0}
diff --git a/llvm/test/Transforms/InstCombine/load.ll b/llvm/test/Transforms/InstCombine/load.ll
index 2cc55e99fd2..cad2899ea35 100644
--- a/llvm/test/Transforms/InstCombine/load.ll
+++ b/llvm/test/Transforms/InstCombine/load.ll
@@ -201,3 +201,21 @@ entry:
ret void
}
+
+; Check that we don't try change the type of the load by inserting a bitcast
+; generating invalid IR.
+; CHECK-LABEL: @test18(
+; CHECK-NOT: bitcast
+; CHECK: ret
+%swift.error = type opaque
+declare void @useSwiftError(%swift.error** swifterror)
+
+define void @test18(%swift.error** swifterror %err) {
+entry:
+ %swifterror = alloca swifterror %swift.error*, align 8
+ store %swift.error* null, %swift.error** %swifterror, align 8
+ call void @useSwiftError(%swift.error** nonnull swifterror %swifterror)
+ %err.res = load %swift.error*, %swift.error** %swifterror, align 8
+ store %swift.error* %err.res, %swift.error** %err, align 8
+ ret void
+}
OpenPOWER on IntegriCloud