Skip to content

Commit cbb617e

Browse files
authored
Merge pull request #3743 from rudkx/inline-asm-when-optimizing
Only emit empty inline asm instructions for cond_fail when optimizing.
2 parents 3b7a5c6 + 122827e commit cbb617e

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,19 +4629,21 @@ void IRGenSILFunction::visitCondFailInst(swift::CondFailInst *i) {
46294629
Builder.CreateCondBr(cond, failBB, contBB);
46304630
Builder.emitBlock(failBB);
46314631

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

46464648
// Emit the trap instruction.
46474649
llvm::Function *trapIntrinsic =

test/IRGen/condfail.sil

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
// RUN: %target-swift-frontend -primary-file %s -O -g -S | FileCheck %s --check-prefix=CHECK-%target-cpu
1+
// 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
2+
// 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
23

34
import Builtin
45
import Swift
56

67
// Make sure we emit two traps.
78

8-
// CHECK-LABEL: _test_cond_fail:
9+
// CHECK-LABEL: test_cond_fail:
910
// CHECK: .cfi_startproc
11+
// CHECK-OPT-macosx: ## InlineAsm Start
12+
// CHECK-OPT-macosx: ## InlineAsm End
13+
// CHECK-OPT-linux: ##APP
14+
// CHECK-OPT-linux: ##NO_APP
15+
// CHECK-NOOPT-macosx-NOT: ## InlineAsm Start
16+
// CHECK-NOOPT-macosx-NOT: ## InlineAsm End
17+
// CHECK-NOOPT-linux-NOT: ##APP
18+
// CHECK-NOOPT-linux-NOT: ##NO_APP
1019
// CHECK-x86_64: ud2
1120
// CHECK-i386: ud2
1221
// CHECK-arm64: brk
@@ -16,6 +25,14 @@ import Swift
1625
// CHECK-powerpc64le: trap
1726
// CHECK-s390x: trap
1827
// CHECK-NOT: .cfi_endproc
28+
// CHECK-OPT-macosx: ## InlineAsm Start
29+
// CHECK-OPT-macosx: ## InlineAsm End
30+
// CHECK-OPT-linux: ##APP
31+
// CHECK-OPT-linux: ##NO_APP
32+
// CHECK-NOOPT-macosx-NOT: ## InlineAsm Start
33+
// CHECK-NOOPT-macosx-NOT: ## InlineAsm End
34+
// CHECK-NOOPT-linux-NOT: ##APP
35+
// CHECK-NOOPT-linux-NOT: ##NO_APP
1936
// CHECK-x86_64: ud2
2037
// CHECK-i386: ud2
2138
// CHECK-arm64: brk

0 commit comments

Comments
 (0)