[PATCH] D104606: llvm-diff: add support for diffing the callbr instruction

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 20 15:00:45 PDT 2021


void created this revision.
void added a reviewer: rjmccall.
void requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The only wrinkle is that we can't process the "blockaddress" arguments
of the callbr until the blocks have been equated. So we force them to be
"unified" before checking.

This was left out when the callbr instruction was added.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104606

Files:
  llvm/test/tools/llvm-diff/callbr.ll
  llvm/tools/llvm-diff/DifferenceEngine.cpp


Index: llvm/tools/llvm-diff/DifferenceEngine.cpp
===================================================================
--- llvm/tools/llvm-diff/DifferenceEngine.cpp
+++ llvm/tools/llvm-diff/DifferenceEngine.cpp
@@ -284,6 +284,27 @@
       }
       return false;
 
+    } else if (isa<CallBrInst>(L)) {
+      CallBrInst &LI = cast<CallBrInst>(*L);
+      CallBrInst &RI = cast<CallBrInst>(*R);
+      if (LI.getNumIndirectDests() != RI.getNumIndirectDests()) {
+        if (Complain)
+          Engine.log("callbr # of indirect destinations differ");
+        return true;
+      }
+
+      // Perform the "try unify" step so that we can equate the indirect
+      // destinations before checking the call site.
+      for (unsigned i = 0; i < LI.getNumIndirectDests(); i++)
+        tryUnify(LI.getIndirectDest(i), RI.getIndirectDest(i));
+
+      if (diffCallSites(LI, RI, Complain))
+        return true;
+
+      if (TryUnify)
+        tryUnify(LI.getDefaultDest(), RI.getDefaultDest());
+      return false;
+
     } else if (isa<BranchInst>(L)) {
       BranchInst *LI = cast<BranchInst>(L);
       BranchInst *RI = cast<BranchInst>(R);
Index: llvm/test/tools/llvm-diff/callbr.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-diff/callbr.ll
@@ -0,0 +1,39 @@
+; RUN: not llvm-diff %s %s 2>&1 | FileCheck %s
+
+define void @foo() {
+entry:
+  callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@foo, %return), i8* blockaddress(@foo, %t_no))
+          to label %asm.fallthrough [label %return, label %t_no]
+
+asm.fallthrough:
+  br label %return
+
+t_no:
+  br label %return
+
+return:
+  ret void
+}
+
+; CHECK:      in function bar:
+; CHECK-NOT:  in function foo:
+; CHECK-NEXT:  in block %entry:
+; CHECK-NEXT:    >   callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@foo, %t_no), i8* blockaddress(@foo, %return))
+; CHECK-NEXT:          to label %asm.fallthrough [label %return, label %t_no]
+; CHECK-NEXT:    <   callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@foo, %t_no), i8* blockaddress(@foo, %return))
+; CHECK-NEXT:          to label %asm.fallthrough [label %return, label %t_no]
+
+define void @bar() {
+entry:
+  callbr void asm sideeffect "", "X,X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@foo, %t_no), i8* blockaddress(@foo, %return))
+          to label %asm.fallthrough [label %return, label %t_no]
+
+asm.fallthrough:
+  br label %return
+
+t_no:
+  br label %return
+
+return:
+  ret void
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104606.353244.patch
Type: text/x-patch
Size: 2580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210620/4ba874ef/attachment.bin>


More information about the llvm-commits mailing list