Skip to content

Commit 3a84a4e

Browse files
authored
Reland "[NVPTX] Unify and extend barrier{.cta} intrinsic support" (#141143)
Note: This relands #140615 adding a ".count" suffix to the non-".all" variants. Our current intrinsic support for barrier intrinsics is confusing and incomplete, with multiple intrinsics mapping to the same instruction and intrinsic names not clearly conveying intrinsic semantics. Further, we lack support for some variants. This change unifies the IR representation to a single consistently named set of intrinsics. - llvm.nvvm.barrier.cta.sync.aligned.all(i32) - llvm.nvvm.barrier.cta.sync.aligned.count(i32, i32) - llvm.nvvm.barrier.cta.arrive.aligned.count(i32, i32) - llvm.nvvm.barrier.cta.sync.all(i32) - llvm.nvvm.barrier.cta.sync.count(i32, i32) - llvm.nvvm.barrier.cta.arrive.count(i32, i32) The following Auto-Upgrade rules are used to maintain compatibility with IR using the legacy intrinsics: * llvm.nvvm.barrier0 --> llvm.nvvm.barrier.cta.sync.aligned.all(0) * llvm.nvvm.barrier.n --> llvm.nvvm.barrier.cta.sync.aligned.all(x) * llvm.nvvm.bar.sync --> llvm.nvvm.barrier.cta.sync.aligned.all(x) * llvm.nvvm.barrier --> llvm.nvvm.barrier.cta.sync.aligned.count(x, y) * llvm.nvvm.barrier.sync --> llvm.nvvm.barrier.cta.sync.all(x) * llvm.nvvm.barrier.sync.cnt --> llvm.nvvm.barrier.cta.sync.count(x, y)
1 parent 5d76555 commit 3a84a4e

File tree

21 files changed

+350
-197
lines changed

21 files changed

+350
-197
lines changed

clang/lib/CodeGen/TargetBuiltins/NVPTX.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,22 @@ Value *CodeGenFunction::EmitNVPTXBuiltinExpr(unsigned BuiltinID,
11601160
case NVPTX::BI__nvvm_fence_sc_cluster:
11611161
return Builder.CreateCall(
11621162
CGM.getIntrinsic(Intrinsic::nvvm_fence_sc_cluster));
1163+
case NVPTX::BI__nvvm_bar_sync:
1164+
return Builder.CreateCall(
1165+
CGM.getIntrinsic(Intrinsic::nvvm_barrier_cta_sync_aligned_all),
1166+
EmitScalarExpr(E->getArg(0)));
1167+
case NVPTX::BI__syncthreads:
1168+
return Builder.CreateCall(
1169+
CGM.getIntrinsic(Intrinsic::nvvm_barrier_cta_sync_aligned_all),
1170+
Builder.getInt32(0));
1171+
case NVPTX::BI__nvvm_barrier_sync:
1172+
return Builder.CreateCall(
1173+
CGM.getIntrinsic(Intrinsic::nvvm_barrier_cta_sync_all),
1174+
EmitScalarExpr(E->getArg(0)));
1175+
case NVPTX::BI__nvvm_barrier_sync_cnt:
1176+
return Builder.CreateCall(
1177+
CGM.getIntrinsic(Intrinsic::nvvm_barrier_cta_sync_count),
1178+
{EmitScalarExpr(E->getArg(0)), EmitScalarExpr(E->getArg(1))});
11631179
default:
11641180
return nullptr;
11651181
}

clang/test/CodeGen/builtins-nvptx-ptx60.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ __device__ void nvvm_sync(unsigned mask, int i, float f, int a, int b,
3232
// CHECK: call void @llvm.nvvm.bar.warp.sync(i32
3333
// expected-error@+1 {{'__nvvm_bar_warp_sync' needs target feature ptx60}}
3434
__nvvm_bar_warp_sync(mask);
35-
// CHECK: call void @llvm.nvvm.barrier.sync(i32
35+
// CHECK: call void @llvm.nvvm.barrier.cta.sync.all(i32
3636
// expected-error@+1 {{'__nvvm_barrier_sync' needs target feature ptx60}}
3737
__nvvm_barrier_sync(mask);
38-
// CHECK: call void @llvm.nvvm.barrier.sync.cnt(i32
38+
// CHECK: call void @llvm.nvvm.barrier.cta.sync.count(i32
3939
// expected-error@+1 {{'__nvvm_barrier_sync_cnt' needs target feature ptx60}}
4040
__nvvm_barrier_sync_cnt(mask, i);
4141

clang/test/CodeGen/builtins-nvptx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ __device__ int read_pms() {
198198

199199
__device__ void sync() {
200200

201-
// CHECK: call void @llvm.nvvm.bar.sync(i32 0)
201+
// CHECK: call void @llvm.nvvm.barrier.cta.sync.aligned.all(i32 0)
202202

203203
__nvvm_bar_sync(0);
204204

@@ -259,7 +259,7 @@ __device__ void nvvm_math(float f1, float f2, double d1, double d2) {
259259
__nvvm_membar_gl();
260260
// CHECK: call void @llvm.nvvm.membar.sys()
261261
__nvvm_membar_sys();
262-
// CHECK: call void @llvm.nvvm.barrier0()
262+
// CHECK: call void @llvm.nvvm.barrier.cta.sync.aligned.all(i32 0)
263263
__syncthreads();
264264
}
265265

clang/test/Headers/gpuintrin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ __gpu_kernel void foo() {
887887
// NVPTX-LABEL: define internal void @__gpu_sync_threads(
888888
// NVPTX-SAME: ) #[[ATTR0]] {
889889
// NVPTX-NEXT: [[ENTRY:.*:]]
890-
// NVPTX-NEXT: call void @llvm.nvvm.barrier0()
890+
// NVPTX-NEXT: call void @llvm.nvvm.barrier.cta.sync.aligned.all(i32 0)
891891
// NVPTX-NEXT: ret void
892892
//
893893
//

llvm/docs/NVPTXUsage.rst

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,59 @@ map in the following way to CUDA builtins:
199199
Barriers
200200
--------
201201

202-
'``llvm.nvvm.barrier0``'
203-
^^^^^^^^^^^^^^^^^^^^^^^^^^^
202+
'``llvm.nvvm.barrier.cta.*``'
203+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
204204

205205
Syntax:
206206
"""""""
207207

208208
.. code-block:: llvm
209209
210-
declare void @llvm.nvvm.barrier0()
210+
declare void @llvm.nvvm.barrier.cta.sync.count(i32 %id, i32 %n)
211+
declare void @llvm.nvvm.barrier.cta.sync.all(i32 %id)
212+
declare void @llvm.nvvm.barrier.cta.arrive.count(i32 %id, i32 %n)
213+
214+
declare void @llvm.nvvm.barrier.cta.sync.aligned.count(i32 %id, i32 %n)
215+
declare void @llvm.nvvm.barrier.cta.sync.aligned.all(i32 %id)
216+
declare void @llvm.nvvm.barrier.cta.arrive.aligned.count(i32 %id, i32 %n)
211217
212218
Overview:
213219
"""""""""
214220

215-
The '``@llvm.nvvm.barrier0()``' intrinsic emits a PTX ``bar.sync 0``
216-
instruction, equivalent to the ``__syncthreads()`` call in CUDA.
221+
The '``@llvm.nvvm.barrier.cta.*``' family of intrinsics perform barrier
222+
synchronization and communication within a CTA. They can be used by the threads
223+
within the CTA for synchronization and communication.
224+
225+
Semantics:
226+
""""""""""
227+
228+
Operand %id specifies a logical barrier resource and must fall within the range
229+
0 through 15. When present, operand %n specifies the number of threads
230+
participating in the barrier. When specifying a thread count, the value must be
231+
a multiple of the warp size. With the '``@llvm.nvvm.barrier.cta.sync.*``'
232+
variants, the '``.all``' suffix indicates that all threads in the CTA should
233+
participate in the barrier while the '``.count``' suffix indicates that only
234+
the threads specified by the %n operand should participate in the barrier.
235+
236+
All forms of the '``@llvm.nvvm.barrier.cta.*``' intrinsic cause the executing
237+
thread to wait for all non-exited threads from its warp and then marks the
238+
warp's arrival at the barrier. In addition to signaling its arrival at the
239+
barrier, the '``@llvm.nvvm.barrier.cta.sync.*``' intrinsics cause the executing
240+
thread to wait for non-exited threads of all other warps participating in the
241+
barrier to arrive. On the other hand, the '``@llvm.nvvm.barrier.cta.arrive.*``'
242+
intrinsic does not cause the executing thread to wait for threads of other
243+
participating warps.
244+
245+
When a barrier completes, the waiting threads are restarted without delay,
246+
and the barrier is reinitialized so that it can be immediately reused.
247+
248+
The '``@llvm.nvvm.barrier.cta.*``' intrinsic has an optional '``.aligned``'
249+
modifier to indicate textual alignment of the barrier. When specified, it
250+
indicates that all threads in the CTA will execute the same
251+
'``@llvm.nvvm.barrier.cta.*``' instruction. In conditionally executed code, an
252+
aligned '``@llvm.nvvm.barrier.cta.*``' instruction should only be used if it is
253+
known that all threads in the CTA evaluate the condition identically, otherwise
254+
behavior is undefined.
217255

218256
Electing a thread
219257
-----------------

llvm/include/llvm/IR/IntrinsicsNVVM.td

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
// * llvm.nvvm.swap.lo.hi.b64 --> llvm.fshl(x, x, 32)
129129
// * llvm.nvvm.atomic.load.inc.32 --> atomicrmw uinc_wrap
130130
// * llvm.nvvm.atomic.load.dec.32 --> atomicrmw udec_wrap
131+
// * llvm.nvvm.barrier0 --> llvm.nvvm.barrier.cta.sync.aligned.all(0)
132+
// * llvm.nvvm.barrier.n --> llvm.nvvm.barrier.cta.sync.aligned.all(x)
133+
// * llvm.nvvm.bar.sync --> llvm.nvvm.barrier.cta.sync.aligned.all(x)
134+
// * llvm.nvvm.barrier --> llvm.nvvm.barrier.cta.sync.aligned(x, y)
135+
// * llvm.nvvm.barrier.sync --> llvm.nvvm.barrier.cta.sync.all(x)
136+
// * llvm.nvvm.barrier.sync.cnt --> llvm.nvvm.barrier.cta.sync(x, y)
131137

132138
def llvm_global_ptr_ty : LLVMQualPointerType<1>; // (global)ptr
133139
def llvm_shared_ptr_ty : LLVMQualPointerType<3>; // (shared)ptr
@@ -1278,35 +1284,28 @@ let TargetPrefix = "nvvm" in {
12781284
defm int_nvvm_atomic_cas_gen_i : PTXAtomicWithScope3<llvm_anyint_ty>;
12791285

12801286
// Bar.Sync
1281-
1282-
// The builtin for "bar.sync 0" is called __syncthreads. Unlike most of the
1283-
// intrinsics in this file, this one is a user-facing API.
1284-
def int_nvvm_barrier0 : ClangBuiltin<"__syncthreads">,
1285-
Intrinsic<[], [], [IntrConvergent, IntrNoCallback]>;
1286-
// Synchronize all threads in the CTA at barrier 'n'.
1287-
def int_nvvm_barrier_n : ClangBuiltin<"__nvvm_bar_n">,
1288-
Intrinsic<[], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
1289-
// Synchronize 'm', a multiple of warp size, (arg 2) threads in
1290-
// the CTA at barrier 'n' (arg 1).
1291-
def int_nvvm_barrier : ClangBuiltin<"__nvvm_bar">,
1292-
Intrinsic<[], [llvm_i32_ty, llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
12931287
def int_nvvm_barrier0_popc : ClangBuiltin<"__nvvm_bar0_popc">,
12941288
Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
12951289
def int_nvvm_barrier0_and : ClangBuiltin<"__nvvm_bar0_and">,
12961290
Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
12971291
def int_nvvm_barrier0_or : ClangBuiltin<"__nvvm_bar0_or">,
12981292
Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
12991293

1300-
def int_nvvm_bar_sync : NVVMBuiltin,
1301-
Intrinsic<[], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
13021294
def int_nvvm_bar_warp_sync : NVVMBuiltin,
13031295
Intrinsic<[], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
13041296

1305-
// barrier.sync id[, cnt]
1306-
def int_nvvm_barrier_sync : NVVMBuiltin,
1307-
Intrinsic<[], [llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
1308-
def int_nvvm_barrier_sync_cnt : NVVMBuiltin,
1309-
Intrinsic<[], [llvm_i32_ty, llvm_i32_ty], [IntrConvergent, IntrNoCallback]>;
1297+
// barrier{.cta}.sync{.aligned} a{, b};
1298+
// barrier{.cta}.arrive{.aligned} a, b;
1299+
let IntrProperties = [IntrConvergent, IntrNoCallback] in {
1300+
foreach align = ["", "_aligned"] in {
1301+
def int_nvvm_barrier_cta_sync # align # _all :
1302+
Intrinsic<[], [llvm_i32_ty]>;
1303+
def int_nvvm_barrier_cta_sync # align # _count :
1304+
Intrinsic<[], [llvm_i32_ty, llvm_i32_ty]>;
1305+
def int_nvvm_barrier_cta_arrive # align # _count :
1306+
Intrinsic<[], [llvm_i32_ty, llvm_i32_ty]>;
1307+
}
1308+
}
13101309

13111310
// barrier.cluster.[wait, arrive, arrive.relaxed]
13121311
def int_nvvm_barrier_cluster_arrive :

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,12 +1343,9 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
13431343
// nvvm.abs.{i,ii}
13441344
Expand =
13451345
Name == "i" || Name == "ll" || Name == "bf16" || Name == "bf16x2";
1346-
else if (Name == "fabs.f" || Name == "fabs.ftz.f" || Name == "fabs.d")
1346+
else if (Name.consume_front("fabs."))
13471347
// nvvm.fabs.{f,ftz.f,d}
1348-
Expand = true;
1349-
else if (Name == "clz.ll" || Name == "popc.ll" || Name == "h2f" ||
1350-
Name == "swap.lo.hi.b64")
1351-
Expand = true;
1348+
Expand = Name == "f" || Name == "ftz.f" || Name == "d";
13521349
else if (Name.consume_front("max.") || Name.consume_front("min."))
13531350
// nvvm.{min,max}.{i,ii,ui,ull}
13541351
Expand = Name == "s" || Name == "i" || Name == "ll" || Name == "us" ||
@@ -1380,7 +1377,18 @@ static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn,
13801377
Expand = (Name.starts_with("i.") || Name.starts_with("f.") ||
13811378
Name.starts_with("p."));
13821379
else
1383-
Expand = false;
1380+
Expand = StringSwitch<bool>(Name)
1381+
.Case("barrier0", true)
1382+
.Case("barrier.n", true)
1383+
.Case("barrier.sync.cnt", true)
1384+
.Case("barrier.sync", true)
1385+
.Case("barrier", true)
1386+
.Case("bar.sync", true)
1387+
.Case("clz.ll", true)
1388+
.Case("popc.ll", true)
1389+
.Case("h2f", true)
1390+
.Case("swap.lo.hi.b64", true)
1391+
.Default(false);
13841392

13851393
if (Expand) {
13861394
NewFn = nullptr;
@@ -2478,6 +2486,21 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
24782486
MDNode *MD = MDNode::get(Builder.getContext(), {});
24792487
LD->setMetadata(LLVMContext::MD_invariant_load, MD);
24802488
return LD;
2489+
} else if (Name == "barrier0" || Name == "barrier.n" || Name == "bar.sync") {
2490+
Value *Arg =
2491+
Name.ends_with('0') ? Builder.getInt32(0) : CI->getArgOperand(0);
2492+
Rep = Builder.CreateIntrinsic(Intrinsic::nvvm_barrier_cta_sync_aligned_all,
2493+
{}, {Arg});
2494+
} else if (Name == "barrier") {
2495+
Rep = Builder.CreateIntrinsic(
2496+
Intrinsic::nvvm_barrier_cta_sync_aligned_count, {},
2497+
{CI->getArgOperand(0), CI->getArgOperand(1)});
2498+
} else if (Name == "barrier.sync") {
2499+
Rep = Builder.CreateIntrinsic(Intrinsic::nvvm_barrier_cta_sync_all, {},
2500+
{CI->getArgOperand(0)});
2501+
} else if (Name == "barrier.sync.cnt") {
2502+
Rep = Builder.CreateIntrinsic(Intrinsic::nvvm_barrier_cta_sync_count, {},
2503+
{CI->getArgOperand(0), CI->getArgOperand(1)});
24812504
} else {
24822505
Intrinsic::ID IID = shouldUpgradeNVPTXBF16Intrinsic(Name);
24832506
if (IID != Intrinsic::not_intrinsic &&

llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ class THREADMASK_INFO<bit sync> {
6767
// Synchronization and shuffle functions
6868
//-----------------------------------
6969
let isConvergent = true in {
70-
def INT_BARRIER0 : NVPTXInst<(outs), (ins),
71-
"bar.sync \t0;",
72-
[(int_nvvm_barrier0)]>;
73-
def INT_BARRIERN : NVPTXInst<(outs), (ins Int32Regs:$src1),
74-
"bar.sync \t$src1;",
75-
[(int_nvvm_barrier_n i32:$src1)]>;
76-
def INT_BARRIER : NVPTXInst<(outs), (ins Int32Regs:$src1, Int32Regs:$src2),
77-
"bar.sync \t$src1, $src2;",
78-
[(int_nvvm_barrier i32:$src1, i32:$src2)]>;
7970
def INT_BARRIER0_POPC : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$pred),
8071
!strconcat("{{ \n\t",
8172
".reg .pred \t%p1; \n\t",
@@ -102,39 +93,51 @@ def INT_BARRIER0_OR : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$pred),
10293
"}}"),
10394
[(set i32:$dst, (int_nvvm_barrier0_or i32:$pred))]>;
10495

105-
def INT_BAR_SYNC : NVPTXInst<(outs), (ins i32imm:$i), "bar.sync \t$i;",
106-
[(int_nvvm_bar_sync imm:$i)]>;
107-
10896
def INT_BAR_WARP_SYNC_I : NVPTXInst<(outs), (ins i32imm:$i), "bar.warp.sync \t$i;",
10997
[(int_nvvm_bar_warp_sync imm:$i)]>,
11098
Requires<[hasPTX<60>, hasSM<30>]>;
11199
def INT_BAR_WARP_SYNC_R : NVPTXInst<(outs), (ins Int32Regs:$i), "bar.warp.sync \t$i;",
112100
[(int_nvvm_bar_warp_sync i32:$i)]>,
113101
Requires<[hasPTX<60>, hasSM<30>]>;
114102

115-
def INT_BARRIER_SYNC_I : NVPTXInst<(outs), (ins i32imm:$i), "barrier.sync \t$i;",
116-
[(int_nvvm_barrier_sync imm:$i)]>,
117-
Requires<[hasPTX<60>, hasSM<30>]>;
118-
def INT_BARRIER_SYNC_R : NVPTXInst<(outs), (ins Int32Regs:$i), "barrier.sync \t$i;",
119-
[(int_nvvm_barrier_sync i32:$i)]>,
120-
Requires<[hasPTX<60>, hasSM<30>]>;
103+
multiclass BARRIER1<string asmstr, Intrinsic intrinsic, list<Predicate> requires = []> {
104+
def _i : BasicNVPTXInst<(outs), (ins i32imm:$i), asmstr,
105+
[(intrinsic imm:$i)]>,
106+
Requires<requires>;
121107

122-
def INT_BARRIER_SYNC_CNT_RR : NVPTXInst<(outs), (ins Int32Regs:$id, Int32Regs:$cnt),
123-
"barrier.sync \t$id, $cnt;",
124-
[(int_nvvm_barrier_sync_cnt i32:$id, i32:$cnt)]>,
125-
Requires<[hasPTX<60>, hasSM<30>]>;
126-
def INT_BARRIER_SYNC_CNT_RI : NVPTXInst<(outs), (ins Int32Regs:$id, i32imm:$cnt),
127-
"barrier.sync \t$id, $cnt;",
128-
[(int_nvvm_barrier_sync_cnt i32:$id, imm:$cnt)]>,
129-
Requires<[hasPTX<60>, hasSM<30>]>;
130-
def INT_BARRIER_SYNC_CNT_IR : NVPTXInst<(outs), (ins i32imm:$id, Int32Regs:$cnt),
131-
"barrier.sync \t$id, $cnt;",
132-
[(int_nvvm_barrier_sync_cnt imm:$id, i32:$cnt)]>,
133-
Requires<[hasPTX<60>, hasSM<30>]>;
134-
def INT_BARRIER_SYNC_CNT_II : NVPTXInst<(outs), (ins i32imm:$id, i32imm:$cnt),
135-
"barrier.sync \t$id, $cnt;",
136-
[(int_nvvm_barrier_sync_cnt imm:$id, imm:$cnt)]>,
137-
Requires<[hasPTX<60>, hasSM<30>]>;
108+
def _r : BasicNVPTXInst<(outs), (ins Int32Regs:$i), asmstr,
109+
[(intrinsic i32:$i)]>,
110+
Requires<requires>;
111+
}
112+
113+
multiclass BARRIER2<string asmstr, Intrinsic intrinsic, list<Predicate> requires = []> {
114+
def _rr : BasicNVPTXInst<(outs), (ins Int32Regs:$i, Int32Regs:$j), asmstr,
115+
[(intrinsic i32:$i, i32:$j)]>,
116+
Requires<requires>;
117+
118+
def _ri : BasicNVPTXInst<(outs), (ins Int32Regs:$i, i32imm:$j), asmstr,
119+
[(intrinsic i32:$i, imm:$j)]>,
120+
Requires<requires>;
121+
122+
def _ir : BasicNVPTXInst<(outs), (ins i32imm:$i, Int32Regs:$j), asmstr,
123+
[(intrinsic imm:$i, i32:$j)]>,
124+
Requires<requires>;
125+
126+
def _ii : BasicNVPTXInst<(outs), (ins i32imm:$i, i32imm:$j), asmstr,
127+
[(intrinsic imm:$i, imm:$j)]>,
128+
Requires<requires>;
129+
}
130+
131+
// Note the "bar.sync" variants could be renamed to the equivalent corresponding
132+
// "barrier.*.aligned" variants. We use the older syntax for compatibility with
133+
// older versions of the PTX ISA.
134+
defm BARRIER_CTA_SYNC_ALIGNED_ALL : BARRIER1<"bar.sync", int_nvvm_barrier_cta_sync_aligned_all>;
135+
defm BARRIER_CTA_SYNC_ALIGNED : BARRIER2<"bar.sync", int_nvvm_barrier_cta_sync_aligned_count>;
136+
defm BARRIER_CTA_ARRIVE_ALIGNED : BARRIER2<"bar.arrive", int_nvvm_barrier_cta_arrive_aligned_count>;
137+
138+
defm BARRIER_CTA_SYNC_ALL : BARRIER1<"barrier.sync", int_nvvm_barrier_cta_sync_all, [hasPTX<60>]>;
139+
defm BARRIER_CTA_SYNC : BARRIER2<"barrier.sync", int_nvvm_barrier_cta_sync_count, [hasPTX<60>]>;
140+
defm BARRIER_CTA_ARRIVE : BARRIER2<"barrier.arrive", int_nvvm_barrier_cta_arrive_count, [hasPTX<60>]>;
138141

139142
class INT_BARRIER_CLUSTER<string variant, Intrinsic Intr,
140143
list<Predicate> Preds = [hasPTX<78>, hasSM<90>]>:

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,8 @@ struct AANoUnwindCallSite final
21502150

21512151
bool AANoSync::isAlignedBarrier(const CallBase &CB, bool ExecutedAligned) {
21522152
switch (CB.getIntrinsicID()) {
2153-
case Intrinsic::nvvm_barrier0:
2153+
case Intrinsic::nvvm_barrier_cta_sync_aligned_all:
2154+
case Intrinsic::nvvm_barrier_cta_sync_aligned_count:
21542155
case Intrinsic::nvvm_barrier0_and:
21552156
case Intrinsic::nvvm_barrier0_or:
21562157
case Intrinsic::nvvm_barrier0_popc:

llvm/test/Analysis/GlobalsModRef/functions_without_nosync.ll

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,15 @@ target triple = "nvptx64-nvidia-cuda"
1111

1212
; CHECK-LABEL: @bar_sync
1313
; CHECK: store
14-
; CHECK: tail call void @llvm.nvvm.bar.sync(i32 0)
14+
; CHECK: tail call void @llvm.nvvm.barrier.cta.sync.aligned.all(i32 0)
1515
; CHECK: load
1616
define dso_local i32 @bar_sync(i32 %0) local_unnamed_addr {
1717
store i32 %0, ptr addrspacecast (ptr addrspace(3) @s to ptr), align 4
18-
tail call void @llvm.nvvm.bar.sync(i32 0)
18+
tail call void @llvm.nvvm.barrier.cta.sync.aligned.all(i32 0)
1919
%2 = load i32, ptr addrspacecast (ptr addrspace(3) @s to ptr), align 4
2020
ret i32 %2
2121
}
2222

23-
declare void @llvm.nvvm.bar.sync(i32) #0
24-
25-
; CHECK-LABEL: @barrier0
26-
; CHECK: store
27-
; CHECK: tail call void @llvm.nvvm.barrier0()
28-
; CHECK: load
29-
define dso_local i32 @barrier0(i32 %0) local_unnamed_addr {
30-
store i32 %0, ptr addrspacecast (ptr addrspace(3) @s to ptr), align 4
31-
tail call void @llvm.nvvm.barrier0()
32-
%2 = load i32, ptr addrspacecast (ptr addrspace(3) @s to ptr), align 4
33-
ret i32 %2
34-
}
35-
36-
declare void @llvm.nvvm.barrier0() #0
23+
declare void @llvm.nvvm.barrier.cta.sync.aligned.all(i32) #0
3724

3825
attributes #0 = { convergent nounwind }

0 commit comments

Comments
 (0)