[llvm] 77eb1b8 - llc: Don't overwrite frame-pointer attribute

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 17:56:56 PST 2020


Author: Matt Arsenault
Date: 2020-01-15T20:56:46-05:00
New Revision: 77eb1b8f63c120f90ba529a5da2d392e165a4bc4

URL: https://github.com/llvm/llvm-project/commit/77eb1b8f63c120f90ba529a5da2d392e165a4bc4
DIFF: https://github.com/llvm/llvm-project/commit/77eb1b8f63c120f90ba529a5da2d392e165a4bc4.diff

LOG: llc: Don't overwrite frame-pointer attribute

Continue making command line flags with matching attribute behavior
consistent.

Added: 
    llvm/test/Other/opt-override-frame-pointer.ll

Modified: 
    llvm/include/llvm/CodeGen/CommandFlags.inc
    llvm/test/CodeGen/AArch64/GlobalISel/tail-call-no-save-fp-lr.ll
    llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
    llvm/test/CodeGen/AArch64/machine-outliner.mir
    llvm/test/CodeGen/ARM/disable-fp-elim.ll
    llvm/test/CodeGen/X86/fp-elim.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/CommandFlags.inc b/llvm/include/llvm/CodeGen/CommandFlags.inc
index 92a925123647..e9cd1f52ceac 100644
--- a/llvm/include/llvm/CodeGen/CommandFlags.inc
+++ b/llvm/include/llvm/CodeGen/CommandFlags.inc
@@ -400,7 +400,8 @@ setFunctionAttributes(StringRef CPU, StringRef Features, Function &F) {
       NewAttrs.addAttribute("target-features", Appended);
     }
   }
-  if (FramePointerUsage.getNumOccurrences() > 0) {
+  if (FramePointerUsage.getNumOccurrences() > 0 &&
+      !F.hasFnAttribute("frame-pointer")) {
     if (FramePointerUsage == llvm::FramePointer::All)
       NewAttrs.addAttribute("frame-pointer", "all");
     else if (FramePointerUsage == llvm::FramePointer::NonLeaf)

diff  --git a/llvm/test/CodeGen/AArch64/GlobalISel/tail-call-no-save-fp-lr.ll b/llvm/test/CodeGen/AArch64/GlobalISel/tail-call-no-save-fp-lr.ll
index 1c3630f42514..e54b3b8c2bcc 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/tail-call-no-save-fp-lr.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/tail-call-no-save-fp-lr.ll
@@ -2,7 +2,7 @@
 ; RUN: llc %s -verify-machineinstrs -mtriple aarch64-apple-darwin -global-isel -global-isel-abort=1 -frame-pointer=non-leaf -o - 2>&1 | FileCheck %s
 
 ; Check that we get a tail call to foo without saving fp/lr.
-define void @bar(i32 %a) #1 {
+define void @bar(i32 %a) {
 ; CHECK-LABEL: bar:
 ; CHECK:       ; %bb.0: ; %entry
 ; CHECK-NEXT:    b _zoo
@@ -18,6 +18,3 @@ define void @zoo(i32 %a) {
 entry:
   ret void
 }
-
-attributes #1 = { "frame-pointer"="all" }
-

diff  --git a/llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll b/llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
index 14c163a6bdc9..7de95ea29e47 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
+++ b/llvm/test/CodeGen/AArch64/aarch64-fix-cortex-a53-835769.ll
@@ -525,8 +525,8 @@ while.cond:
   br label %while.cond
 }
 
-attributes #0 = { nounwind readonly "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { nounwind "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #0 = { nounwind readonly "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
 attributes #2 = { nounwind }
 
 

diff  --git a/llvm/test/CodeGen/AArch64/machine-outliner.mir b/llvm/test/CodeGen/AArch64/machine-outliner.mir
index 1157a2815560..83eda744d24a 100644
--- a/llvm/test/CodeGen/AArch64/machine-outliner.mir
+++ b/llvm/test/CodeGen/AArch64/machine-outliner.mir
@@ -15,7 +15,7 @@
     ret void
   }
 
-  attributes #0 = { noinline noredzone "frame-pointer"="all" }
+  attributes #0 = { noinline noredzone }
 ...
 ---
 # This test ensures that we

diff  --git a/llvm/test/CodeGen/ARM/disable-fp-elim.ll b/llvm/test/CodeGen/ARM/disable-fp-elim.ll
index 82a5e149c816..513fdcc5b6ed 100644
--- a/llvm/test/CodeGen/ARM/disable-fp-elim.ll
+++ b/llvm/test/CodeGen/ARM/disable-fp-elim.ll
@@ -1,16 +1,16 @@
-; RUN: llc < %s -mtriple armv7-none-linux-gnueabi -O1 | FileCheck %s --check-prefix=DISABLE-FP-ELIM
+; RUN: llc < %s -mtriple armv7-none-linux-gnueabi -fast-isel -O1 | FileCheck %s --check-prefix=DISABLE-FP-ELIM
 ; RUN: llc < %s -mtriple armv7-none-linux-gnueabi -frame-pointer=all -O1 | FileCheck %s --check-prefix=DISABLE-FP-ELIM
 ; RUN: llc < %s -mtriple armv7-none-linux-gnueabi -frame-pointer=none -O1 | FileCheck %s --check-prefix=ENABLE-FP-ELIM
 ; RUN: llc < %s -mtriple armv7-none-linux-gnueabi -frame-pointer=none -O0 | FileCheck %s --check-prefix=DISABLE-FP-ELIM
 
-; Check that command line option "-frame-pointer=all" overrides function attribute
-; "frame-pointer"="all". Also, check frame pointer elimination is disabled
-; when fast-isel is used.
+; Check that command line option "-frame-pointer=all" sets function
+; attribute "frame-pointer"="all". Also, check frame pointer
+; elimination is disabled when fast-isel is used.
 
 ; ENABLE-FP-ELIM-NOT: .setfp
 ; DISABLE-FP-ELIM: .setfp r11, sp
 
-define i32 @foo1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) #0 {
+define i32 @foo1(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
 entry:
   %call = tail call i32 @foo2(i32 %a)
   %add = add i32 %c, %b
@@ -21,5 +21,3 @@ entry:
 }
 
 declare i32 @foo2(i32)
-
-attributes #0 = { nounwind "frame-pointer"="all" }

diff  --git a/llvm/test/CodeGen/X86/fp-elim.ll b/llvm/test/CodeGen/X86/fp-elim.ll
index b644631d1d4b..ba1416551735 100644
--- a/llvm/test/CodeGen/X86/fp-elim.ll
+++ b/llvm/test/CodeGen/X86/fp-elim.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mtriple=i686-- -asm-verbose=false                           | FileCheck %s -check-prefix=FP-ELIM
-; RUN: llc < %s -mtriple=i686-- -asm-verbose=false -frame-pointer=all          | FileCheck %s -check-prefix=NO-ELIM
+; RUN: llc < %s -mtriple=i686-- -asm-verbose=false                           | FileCheck %s -check-prefixes=FP-ELIM,ANY
+; RUN: llc < %s -mtriple=i686-- -asm-verbose=false -frame-pointer=all        | FileCheck %s -check-prefixes=NO-ELIM,ANY
 
 ; Implement -momit-leaf-frame-pointer
 ; rdar://7886181
@@ -31,30 +31,21 @@ entry:
   ret void
 }
 
+; The local non-leaf attribute takes precendece over the command line flag.
 define i32 @t3() "frame-pointer"="non-leaf" nounwind readnone {
 entry:
-; FP-ELIM-LABEL:  t3:
-; FP-ELIM-NEXT:     movl
-; FP-ELIM-NEXT:     ret
-
-; NO-ELIM-LABEL:  t3:
-; NO-ELIM-NEXT:     pushl %ebp
-; NO-ELIM:          popl %ebp
-; NO-ELIM-NEXT:     ret
+; ANY-ELIM-LABEL:  t3:
+; ANY-ELIM-NEXT:     movl
+; ANY-ELIM-NEXT:     ret
   ret i32 10
 }
 
 define void @t4() "frame-pointer"="non-leaf" nounwind {
 entry:
-; FP-ELIM-LABEL:  t4:
-; FP-ELIM-NEXT:     pushl %ebp
-; FP-ELIM:          popl %ebp
-; FP-ELIM-NEXT:     ret
-
-; NO-ELIM-LABEL:  t4:
-; NO-ELIM-NEXT:     pushl %ebp
-; NO-ELIM:          popl %ebp
-; NO-ELIM-NEXT:     ret
+; ANY-ELIM-LABEL:  t4:
+; ANY-ELIM-NEXT:     pushl %ebp
+; ANY-ELIM:          popl %ebp
+; ANY-ELIM-NEXT:     ret
   tail call void @foo(i32 0) nounwind
   ret void
 }

diff  --git a/llvm/test/Other/opt-override-frame-pointer.ll b/llvm/test/Other/opt-override-frame-pointer.ll
new file mode 100644
index 000000000000..804f6f3d910a
--- /dev/null
+++ b/llvm/test/Other/opt-override-frame-pointer.ll
@@ -0,0 +1,50 @@
+; RUN: opt < %s -mtriple=x86_64-apple-darwin -frame-pointer=all -S | FileCheck -check-prefixes=ALL,CHECK %s
+; RUN: opt < %s -mtriple=x86_64-apple-darwin -frame-pointer=none -S | FileCheck -check-prefixes=NONE,CHECK %s
+; RUN: opt < %s -mtriple=x86_64-apple-darwin -frame-pointer=non-leaf -S | FileCheck -check-prefixes=NONLEAF,CHECK %s
+
+; Check behavior of -frame-pointer flag and frame-pointer atttribute.
+
+; CHECK: @no_frame_pointer_attr() [[VARATTR:#[0-9]+]] {
+define i32 @no_frame_pointer_attr() #0 {
+entry:
+  ret i32 0
+}
+
+; CHECK: @frame_pointer_attr_all() [[ALL_ATTR:#[0-9]+]] {
+define i32 @frame_pointer_attr_all() #1 {
+entry:
+  ret i32 0
+}
+
+; CHECK: @frame_pointer_attr_none() [[NONE_ATTR:#[0-9]+]] {
+define i32 @frame_pointer_attr_none() #2 {
+entry:
+  ret i32 0
+}
+
+; CHECK: @frame_pointer_attr_leaf() [[NONLEAF_ATTR:#[0-9]+]] {
+define i32 @frame_pointer_attr_leaf() #3 {
+entry:
+  ret i32 0
+}
+
+; ALL-DAG: attributes [[VARATTR]] = { nounwind "frame-pointer"="all" }
+; ALL-DAG: attributes [[NONE_ATTR]] = { nounwind "frame-pointer"="none" }
+; ALL-DAG: attributes [[NONLEAF_ATTR]] = { nounwind "frame-pointer"="non-leaf" }
+; ALL-NOT: attributes
+
+; NONE-DAG: attributes [[VARATTR]] = { nounwind "frame-pointer"="none" }
+; NONE-DAG: attributes [[ALL_ATTR]] = { nounwind "frame-pointer"="all" }
+; NONE-DAG: attributes [[NONLEAF_ATTR]] = { nounwind "frame-pointer"="non-leaf" }
+; NONE-NOT: attributes
+
+; NONLEAF-DAG: attributes [[VARATTR]] = { nounwind "frame-pointer"="non-leaf" }
+; NONLEAF-DAG: attributes [[ALL_ATTR]] = { nounwind "frame-pointer"="all" }
+; NONLEAF-DAG: attributes [[NONE_ATTR]] = { nounwind "frame-pointer"="none" }
+; NONLEAF-NOT: attributes
+
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind "frame-pointer"="all" }
+attributes #2 = { nounwind "frame-pointer"="none" }
+attributes #3 = { nounwind "frame-pointer"="non-leaf" }


        


More information about the llvm-commits mailing list