[llvm] 6a6db74 - [BPF] Propagate NoMerge attribute when lowering function calls

Eduard Zingerman via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 15:23:07 PDT 2023


Author: Eduard Zingerman
Date: 2023-06-27T01:15:45+03:00
New Revision: 6a6db74b77130874f9fd03b366ae77feab746dd7

URL: https://github.com/llvm/llvm-project/commit/6a6db74b77130874f9fd03b366ae77feab746dd7
DIFF: https://github.com/llvm/llvm-project/commit/6a6db74b77130874f9fd03b366ae77feab746dd7.diff

LOG: [BPF] Propagate NoMerge attribute when lowering function calls

`NoMerge` attribute on machine instructions prevents certain
transformations from merging these instructions.
One of such transformations is 'llvm/lib/CodeGen/BranchFolding.cpp'.

This attribute should be copied from IR `call` instructions to machine
level instructions. See `X86TargetLowering::LowerCall` as another
example.

Differential Revision: https://reviews.llvm.org/D152987

Added: 
    llvm/test/CodeGen/BPF/no-merge-attr.ll

Modified: 
    llvm/lib/Target/BPF/BPFISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp b/llvm/lib/Target/BPF/BPFISelLowering.cpp
index 48f2b21d95990..83a4bfb2f7584 100644
--- a/llvm/lib/Target/BPF/BPFISelLowering.cpp
+++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp
@@ -485,6 +485,8 @@ SDValue BPFTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
   Chain = DAG.getNode(BPFISD::CALL, CLI.DL, NodeTys, Ops);
   InGlue = Chain.getValue(1);
 
+  DAG.addNoMergeSiteInfo(Chain.getNode(), CLI.NoMerge);
+
   // Create the CALLSEQ_END node.
   Chain = DAG.getCALLSEQ_END(Chain, NumBytes, 0, InGlue, CLI.DL);
   InGlue = Chain.getValue(1);

diff  --git a/llvm/test/CodeGen/BPF/no-merge-attr.ll b/llvm/test/CodeGen/BPF/no-merge-attr.ll
new file mode 100644
index 0000000000000..b5c43ace2bab1
--- /dev/null
+++ b/llvm/test/CodeGen/BPF/no-merge-attr.ll
@@ -0,0 +1,51 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+;
+; Source:
+;   extern void foo(void) __attribute__((nomerge));
+;
+;   void bar(long i) {
+;     if (i)
+;       foo();
+;     else
+;       foo();
+;   }
+;
+; Compilation flag:
+;   clang -target bpf -S -O2 -emit-llvm t.c -o t.ll
+
+; The goal of the test is to check that 'nomerge' attribute
+; preserves two calls to 'foo' from merging.
+
+; CHECK:     call foo
+; CHECK:     call foo
+
+; Function Attrs: nounwind
+define dso_local void @bar(i64 noundef %i) local_unnamed_addr #0 {
+entry:
+  %tobool.not = icmp eq i64 %i, 0
+  br i1 %tobool.not, label %if.else, label %if.then
+
+if.then:                                          ; preds = %entry
+  tail call void @foo() #2
+  br label %if.end
+
+if.else:                                          ; preds = %entry
+  tail call void @foo() #2
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+  ret void
+}
+
+declare dso_local void @foo() local_unnamed_addr #1
+
+attributes #0 = { nounwind "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
+attributes #2 = { nomerge nounwind }
+
+!llvm.module.flags = !{!0, !1}
+!llvm.ident = !{!2}
+
+!0 = !{i32 1, !"wchar_size", i32 4}
+!1 = !{i32 7, !"frame-pointer", i32 2}
+!2 = !{!"clang version 17.0.0 (/home/eddy/work/llvm-project/clang bd66f4b1da304af8e5a890b3205ce6f3d76667ee)"}


        


More information about the llvm-commits mailing list