Skip to content

Only emit empty inline asm instructions for cond_fail when optimizing. #3743

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 1 commit into from
Jul 27, 2016
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
28 changes: 15 additions & 13 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4629,19 +4629,21 @@ void IRGenSILFunction::visitCondFailInst(swift::CondFailInst *i) {
Builder.CreateCondBr(cond, failBB, contBB);
Builder.emitBlock(failBB);

// Emit unique side-effecting inline asm calls in order to eliminate
// the possibility that an LLVM optimization or code generation pass
// will merge these blocks back together again. We emit an empty asm
// string with the side-effect flag set, and with a unique integer
// argument for each cond_fail we see in the function.
llvm::IntegerType *asmArgTy = IGM.Int32Ty;
llvm::Type *argTys = { asmArgTy };
llvm::FunctionType *asmFnTy =
llvm::FunctionType::get(IGM.VoidTy, argTys, false /* = isVarArg */);
llvm::InlineAsm *inlineAsm =
llvm::InlineAsm::get(asmFnTy, "", "n", true /* = SideEffects */);
Builder.CreateCall(inlineAsm,
llvm::ConstantInt::get(asmArgTy, NumCondFails++));
if (IGM.IRGen.Opts.Optimize) {
// Emit unique side-effecting inline asm calls in order to eliminate
// the possibility that an LLVM optimization or code generation pass
// will merge these blocks back together again. We emit an empty asm
// string with the side-effect flag set, and with a unique integer
// argument for each cond_fail we see in the function.
llvm::IntegerType *asmArgTy = IGM.Int32Ty;
llvm::Type *argTys = { asmArgTy };
llvm::FunctionType *asmFnTy =
llvm::FunctionType::get(IGM.VoidTy, argTys, false /* = isVarArg */);
llvm::InlineAsm *inlineAsm =
llvm::InlineAsm::get(asmFnTy, "", "n", true /* = SideEffects */);
Builder.CreateCall(inlineAsm,
llvm::ConstantInt::get(asmArgTy, NumCondFails++));
}

// Emit the trap instruction.
llvm::Function *trapIntrinsic =
Expand Down
21 changes: 19 additions & 2 deletions test/IRGen/condfail.sil
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// RUN: %target-swift-frontend -primary-file %s -O -g -S | FileCheck %s --check-prefix=CHECK-%target-cpu
// RUN: %target-swift-frontend -primary-file %s -O -g -S | FileCheck %s --check-prefix CHECK --check-prefix CHECK-%target-cpu --check-prefix CHECK-OPT-%target-os
// RUN: %target-swift-frontend -primary-file %s -g -S | FileCheck %s --check-prefix CHECK --check-prefix CHECK-%target-cpu --check-prefix CHECK-NOOPT-%target-os

import Builtin
import Swift

// Make sure we emit two traps.

// CHECK-LABEL: _test_cond_fail:
// CHECK-LABEL: test_cond_fail:
// CHECK: .cfi_startproc
// CHECK-OPT-macosx: ## InlineAsm Start
// CHECK-OPT-macosx: ## InlineAsm End
// CHECK-OPT-linux: ##APP
// CHECK-OPT-linux: ##NO_APP
// CHECK-NOOPT-macosx-NOT: ## InlineAsm Start
// CHECK-NOOPT-macosx-NOT: ## InlineAsm End
// CHECK-NOOPT-linux-NOT: ##APP
// CHECK-NOOPT-linux-NOT: ##NO_APP
// CHECK-x86_64: ud2
// CHECK-i386: ud2
// CHECK-arm64: brk
Expand All @@ -16,6 +25,14 @@ import Swift
// CHECK-powerpc64le: trap
// CHECK-s390x: trap
// CHECK-NOT: .cfi_endproc
// CHECK-OPT-macosx: ## InlineAsm Start
// CHECK-OPT-macosx: ## InlineAsm End
// CHECK-OPT-linux: ##APP
// CHECK-OPT-linux: ##NO_APP
// CHECK-NOOPT-macosx-NOT: ## InlineAsm Start
// CHECK-NOOPT-macosx-NOT: ## InlineAsm End
// CHECK-NOOPT-linux-NOT: ##APP
// CHECK-NOOPT-linux-NOT: ##NO_APP
// CHECK-x86_64: ud2
// CHECK-i386: ud2
// CHECK-arm64: brk
Expand Down