Skip to content

FastISel: do not fold a swifterror load into anything. #2631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,12 @@ bool FastISel::tryToFoldLoad(const LoadInst *LI, const Instruction *FoldInst) {
if (LI->isVolatile())
return false;

// Swifterror loads are not actually loads.
if (auto AI = dyn_cast<AllocaInst>(LI->getPointerOperand())) {
if (AI->isSwiftError())
return false;
}

// Figure out which vreg this is going into. If there is no assigned vreg yet
// then there actually was no reference to it. Perhaps the load is referenced
// by a dead instruction.
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/X86/swifterror-O0.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: llc -mtriple=x86_64-apple-darwin -O0 %s -o - | FileCheck %s

define i32 @foo() {
; CHECK-LABEL: foo:
; CHECK: cmpq $0, %r12

%swifterror = alloca swifterror i8*
call void @callee(i8** swifterror %swifterror)
%err = load i8*, i8** %swifterror
%tst = icmp ne i8* %err, null
br i1 %tst, label %true, label %false

true:
ret i32 0

false:
ret i32 1
}

declare void @callee(i8** swifterror)