[llvm] [RFC][InstCombine] Combine fence with target specific sync scope (PR #93939)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 01:48:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Ruiling, Song (ruiling)

<details>
<summary>Changes</summary>

I am not quite confident whether this is correct, so want to get feedback on this.

---
Full diff: https://github.com/llvm/llvm-project/pull/93939.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+2-4) 
- (modified) llvm/test/Transforms/InstCombine/consecutive-fences.ll (+9) 


``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index b6f339da31f7f..40393b0c73f74 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3525,10 +3525,8 @@ Instruction *InstCombinerImpl::visitFenceInst(FenceInst &FI) {
   // Returns true if FI1 is identical or stronger fence than FI2.
   auto isIdenticalOrStrongerFence = [](FenceInst *FI1, FenceInst *FI2) {
     auto FI1SyncScope = FI1->getSyncScopeID();
-    // Consider same scope, where scope is global or single-thread.
-    if (FI1SyncScope != FI2->getSyncScopeID() ||
-        (FI1SyncScope != SyncScope::System &&
-         FI1SyncScope != SyncScope::SingleThread))
+    // Consider same scope, including target specific syncscope.
+    if (FI1SyncScope != FI2->getSyncScopeID())
       return false;
 
     return isAtLeastOrStrongerThan(FI1->getOrdering(), FI2->getOrdering());
diff --git a/llvm/test/Transforms/InstCombine/consecutive-fences.ll b/llvm/test/Transforms/InstCombine/consecutive-fences.ll
index ce8274811416c..482e720dd4de6 100644
--- a/llvm/test/Transforms/InstCombine/consecutive-fences.ll
+++ b/llvm/test/Transforms/InstCombine/consecutive-fences.ll
@@ -30,6 +30,15 @@ define void @test_target_dependent_scope() {
   ret void
 }
 
+; CHECK-LABEL: combine_target_dependent_scope
+; CHECK-NEXT: fence syncscope("agent") seq_cst
+; CHECK-NEXT: ret void
+define void @combine_target_dependent_scope() {
+  fence syncscope("agent") acq_rel
+  fence syncscope("agent") seq_cst
+  ret void
+}
+
 ; CHECK-LABEL: define void @dipsy
 ; CHECK-NEXT:   fence seq_cst
 ; CHECK-NEXT:   fence syncscope("singlethread") seq_cst

``````````

</details>


https://github.com/llvm/llvm-project/pull/93939


More information about the llvm-commits mailing list