[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:47:58 PDT 2024
https://github.com/ruiling created https://github.com/llvm/llvm-project/pull/93939
I am not quite confident whether this is correct, so want to get feedback on this.
>From 719ed0d1392f955e311949752d17f2fed7e5e0c8 Mon Sep 17 00:00:00 2001
From: Ruiling Song <ruiling.song at amd.com>
Date: Fri, 31 May 2024 16:37:44 +0800
Subject: [PATCH] [RFC][InstCombine] Combine fence with target specific sync
scope
---
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 6 ++----
llvm/test/Transforms/InstCombine/consecutive-fences.ll | 9 +++++++++
2 files changed, 11 insertions(+), 4 deletions(-)
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
More information about the llvm-commits
mailing list