Skip to content

Commit 43bfec2

Browse files
authored
[flang][cuda] Fix condition in barrier_try_wait lowering (#171916)
The condition should have been while 0 then try to wait and not the opposite.
1 parent 20cc9fe commit 43bfec2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

flang/lib/Optimizer/Builder/CUDAIntrinsicCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ CUDAIntrinsicLibrary::genBarrierTryWait(mlir::Type resultType,
10101010
mlir::Value beforeArg = beforeBlock->addArgument(resultType, loc);
10111011
builder.setInsertionPointToStart(beforeBlock);
10121012
mlir::Value condition = mlir::arith::CmpIOp::create(
1013-
builder, loc, mlir::arith::CmpIPredicate::ne, beforeArg, zero);
1013+
builder, loc, mlir::arith::CmpIPredicate::eq, beforeArg, zero);
10141014
mlir::scf::ConditionOp::create(builder, loc, condition, beforeArg);
10151015
mlir::Block *afterBlock = builder.createBlock(&whileOp.getAfter());
10161016
afterBlock->addArgument(resultType, loc);

flang/test/Lower/CUDA/cuda-device-proc.cuf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,8 @@ end subroutine
513513

514514
! CHECK-LABEL: func.func @_QPtest_barrier_try_wait()
515515
! CHECK: scf.while
516+
! CHECK: %[[COND:.*]] = arith.cmpi eq
517+
! CHECK: scf.condition(%[[COND]])
516518
! CHECK: %{{.*}} = nvvm.inline_ptx "{\0A .reg .pred p;\0A mbarrier.try_wait.shared.b64 p, [%{{.*}}], %{{.*}}, %{{.*}};\0A selp.b32 %{{.*}}, 1, 0, p;\0A}" ro(%{{.*}}, %{{.*}}, %{{.*}} : !llvm.ptr, i64, i32) -> i32
517519

518520
attributes(global) subroutine test_barrier_try_wait_sleep()

0 commit comments

Comments
 (0)