[llvm] [LLVM] convergence verifier should visit all instructions (PR #66200)

Sameer Sahasrabuddhe via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 05:11:38 PDT 2023


https://github.com/ssahasra created https://github.com/llvm/llvm-project/pull/66200:

The entry and loop intrinsics for convergence control cannot be preceded by convergent operations in their respective basic blocks. To check that, the verifier needs to reset its state at the start of the block. This was missed in the previous commit fa6dd7a24af2b02f236ec3b980d9407e86c2c4aa.

>From 9c22a62ae4231fe97b93fdc2e3fae413bca3d503 Mon Sep 17 00:00:00 2001
From: Sameer Sahasrabuddhe <sameer.sahasrabuddhe at amd.com>
Date: Wed, 13 Sep 2023 16:36:36 +0530
Subject: [PATCH] [LLVM] convergence verifier should visit all instructions

The entry and loop intrinsics for convergence control cannot be preceded by
convergent operations in their respective basic blocks. To check that, the
verifier needs to reset its state at the start of the block. This was missed in
the previous commit fa6dd7a24af2b02f236ec3b980d9407e86c2c4aa.
---
 llvm/lib/IR/Verifier.cpp                      | 4 ++--
 llvm/test/Verifier/convergencectrl-invalid.ll | 7 ++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index c0f30a62b8bccc3..9ed66e6af68fbfc 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3576,8 +3576,6 @@ void Verifier::visitCallBase(CallBase &Call) {
   if (Call.isInlineAsm())
     verifyInlineAsmCall(Call);
 
-  CV.visit(Call);
-
   visitInstruction(Call);
 }
 
@@ -4805,6 +4803,8 @@ void Verifier::visitInstruction(Instruction &I) {
   BasicBlock *BB = I.getParent();
   Check(BB, "Instruction not embedded in basic block!", &I);
 
+  CV.visit(I);
+
   if (!isa<PHINode>(I)) {   // Check that non-phi nodes are not self referential
     for (User *U : I.users()) {
       Check(U != (User *)&I || !DT.isReachableFromEntry(BB),
diff --git a/llvm/test/Verifier/convergencectrl-invalid.ll b/llvm/test/Verifier/convergencectrl-invalid.ll
index 2f7b311973d7e1e..e1fffcd1c603347 100644
--- a/llvm/test/Verifier/convergencectrl-invalid.ll
+++ b/llvm/test/Verifier/convergencectrl-invalid.ll
@@ -126,13 +126,18 @@ define void @entry_in_convergent(i32 %x, i32 %y) {
 }
 
 ; CHECK: Loop intrinsic cannot be preceded by a convergent operation in the same basic block.
-; CHECK:   %t60_tok3
+; CHECK-NEXT: %h1
+; CHECK-SAME: %t60_tok3
 define void @loop_at_start(i32 %x, i32 %y) convergent {
 A:
   %t60_tok3 = call token @llvm.experimental.convergence.entry()
   br label %B
 B:
   %z = add i32 %x, %y
+  ; This is not an error
+  %h2 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %t60_tok3) ]
+  br label %C
+C:
   call void @f()
   %h1 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %t60_tok3) ]
   ret void



More information about the llvm-commits mailing list