diff options
| author | Jessica Paquette <jpaquette@apple.com> | 2018-04-03 23:32:41 +0000 |
|---|---|---|
| committer | Jessica Paquette <jpaquette@apple.com> | 2018-04-03 23:32:41 +0000 |
| commit | 5fa2a63785d6e07029887317df6a8d7ff144bbbd (patch) | |
| tree | ba41349741e77179d96c9c51c6e8218ae4d0c0d7 | |
| parent | b92b10f3ec4897c07655aab0999817ba503ebf71 (diff) | |
| download | bcm5719-llvm-5fa2a63785d6e07029887317df6a8d7ff144bbbd.tar.gz bcm5719-llvm-5fa2a63785d6e07029887317df6a8d7ff144bbbd.zip | |
[MachineOutliner] Test for X86FI->getUsesRedZone() as well as Attribute::NoRedZone
This commit is similar to r329120, but uses the existing getUsesRedZone() function
in X86MachineFunctionInfo. This teaches the outliner to look at whether or not a
function *truly* uses a redzone instead of just the noredzone attribute on a
function.
Thus, after this commit, it's possible to outline from x86 without using
-mno-red-zone and still get outlining results.
This also adds a new test for the new redzone behaviour.
llvm-svn: 329134
| -rw-r--r-- | llvm/lib/Target/X86/X86InstrInfo.cpp | 6 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/machine-outliner-noredzone.ll | 70 |
2 files changed, 75 insertions, 1 deletions
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp index f5aeb3f10fc..94a0bee7e8e 100644 --- a/llvm/lib/Target/X86/X86InstrInfo.cpp +++ b/llvm/lib/Target/X86/X86InstrInfo.cpp @@ -11198,8 +11198,12 @@ bool X86InstrInfo::isFunctionSafeToOutlineFrom(MachineFunction &MF, // Does the function use a red zone? If it does, then we can't risk messing // with the stack. - if (!F.hasFnAttribute(Attribute::NoRedZone)) + if (!F.hasFnAttribute(Attribute::NoRedZone)) { + // It could have a red zone. If it does, then we don't want to touch it. + const X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); + if (!X86FI || X86FI->getUsesRedZone()) return false; + } // If we *don't* want to outline from things that could potentially be deduped // then return false. diff --git a/llvm/test/CodeGen/X86/machine-outliner-noredzone.ll b/llvm/test/CodeGen/X86/machine-outliner-noredzone.ll new file mode 100644 index 00000000000..94271e30bdf --- /dev/null +++ b/llvm/test/CodeGen/X86/machine-outliner-noredzone.ll @@ -0,0 +1,70 @@ +; RUN: llc -enable-machine-outliner -mtriple=x86_64-apple-darwin < %s | FileCheck %s +; Ensure that the outliner doesn't outline from any functions that use a redzone. + +declare i8* @llvm.stacksave() #1 +declare void @llvm.stackrestore(i8*) #1 + +; This function has a red zone. We shouldn't outline from it. +; CHECK-LABEL: doggo +; CHECK-NOT: OUTLINED +define void @doggo(i32) #0 { + %2 = alloca i32, align 4 + store i32 %0, i32* %2, align 4 + %3 = load i32, i32* %2, align 4 + %4 = add nsw i32 %3, 1 + store i32 %4, i32* %2, align 4 + ret void +} + +; Ditto. +; CHECK-LABEL: pupper +; CHECK-NOT: OUTLINED +define void @pupper(i32) #0 { + %2 = alloca i32, align 4 + store i32 %0, i32* %2, align 4 + %3 = load i32, i32* %2, align 4 + %4 = add nsw i32 %3, 1 + store i32 %4, i32* %2, align 4 + ret void +} + +; This doesn't have a redzone. Outlining is okay. +; CHECK-LABEL: boofer +; CHECK: OUTLINED +define void @boofer(i32) #0 { + %2 = alloca i32, align 4 + %3 = alloca i8*, align 8 + %4 = alloca i64, align 8 + store i32 %0, i32* %2, align 4 + %5 = load i32, i32* %2, align 4 + %6 = zext i32 %5 to i64 + %7 = call i8* @llvm.stacksave() + store i8* %7, i8** %3, align 8 + %8 = alloca i32, i64 %6, align 16 + store i64 %6, i64* %4, align 8 + %9 = load i8*, i8** %3, align 8 + call void @llvm.stackrestore(i8* %9) + ret void +} + +; Ditto. +; CHECK-LABEL: shibe +; CHECK: OUTLINED +define void @shibe(i32) #0 { + %2 = alloca i32, align 4 + %3 = alloca i8*, align 8 + %4 = alloca i64, align 8 + store i32 %0, i32* %2, align 4 + %5 = load i32, i32* %2, align 4 + %6 = zext i32 %5 to i64 + %7 = call i8* @llvm.stacksave() + store i8* %7, i8** %3, align 8 + %8 = alloca i32, i64 %6, align 16 + store i64 %6, i64* %4, align 8 + %9 = load i8*, i8** %3, align 8 + call void @llvm.stackrestore(i8* %9) + ret void +} + +attributes #0 = { noinline nounwind optnone ssp uwtable "no-frame-pointer-elim"="true" } +attributes #1 = { nounwind }
\ No newline at end of file |

