diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index 388c5e4e7fa4e..49e516e9c1761 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -502,7 +502,8 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) { !DL.isNonIntegralPointerType(Ty)) { if (all_of(LI.users(), [&LI](User *U) { auto *SI = dyn_cast(U); - return SI && SI->getPointerOperand() != &LI; + return SI && SI->getPointerOperand() != &LI && + !SI->getPointerOperand()->isSwiftError(); })) { LoadInst *NewLoad = combineLoadToNewType( IC, LI, diff --git a/llvm/test/Transforms/InstCombine/load.ll b/llvm/test/Transforms/InstCombine/load.ll index cad2899ea35d6..49ed897fd2ead 100644 --- a/llvm/test/Transforms/InstCombine/load.ll +++ b/llvm/test/Transforms/InstCombine/load.ll @@ -219,3 +219,22 @@ entry: store %swift.error* %err.res, %swift.error** %err, align 8 ret void } + +; Make sure we preseve the type of the store to a swifterror pointer. +; CHECK-LABEL: @test19( +; CHECK: [[A:%.*]] = alloca +; CHECK: call +; CHECK: [[BC:%.*]] = bitcast i8** [[A]] to +; CHECK: [[ERRVAL:%.*]] = load {{.*}}[[BC]] +; CHECK: store {{.*}}[[ERRVAL]] +; CHECK: ret +declare void @initi8(i8**) +define void @test19(%swift.error** swifterror %err) { +entry: + %tmp = alloca i8*, align 8 + call void @initi8(i8** %tmp) + %swifterror = bitcast i8** %tmp to %swift.error** + %err.res = load %swift.error*, %swift.error** %swifterror, align 8 + store %swift.error* %err.res, %swift.error** %err, align 8 + ret void +}