[llvm] ab60028 - [llvm-diff] Add support for diffing the callbr instruction

Bill Wendling via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 22 12:24:07 PDT 2021


Author: Bill Wendling
Date: 2021-06-22T12:23:37-07:00
New Revision: ab6002871d837490ed333ed9ff4993cb75964cad

URL: https://github.com/llvm/llvm-project/commit/ab6002871d837490ed333ed9ff4993cb75964cad
DIFF: https://github.com/llvm/llvm-project/commit/ab6002871d837490ed333ed9ff4993cb75964cad.diff

LOG: [llvm-diff] Add support for diffing the callbr instruction

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.

Differential Revision: https://reviews.llvm.org/D104606

Added: 
    llvm/test/tools/llvm-diff/callbr.ll

Modified: 
    llvm/tools/llvm-diff/DifferenceEngine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-
diff /callbr.ll b/llvm/test/tools/llvm-
diff /callbr.ll
new file mode 100644
index 0000000000000..51cdc9ec39a4b
--- /dev/null
+++ b/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
+}

diff  --git a/llvm/tools/llvm-
diff /DifferenceEngine.cpp b/llvm/tools/llvm-
diff /DifferenceEngine.cpp
index c215fb99399a9..326d572d7288e 100644
--- a/llvm/tools/llvm-
diff /DifferenceEngine.cpp
+++ b/llvm/tools/llvm-
diff /DifferenceEngine.cpp
@@ -287,6 +287,27 @@ class FunctionDifferenceEngine {
       }
       return false;
 
+    } else if (isa<CallBrInst>(L)) {
+      const CallBrInst &LI = cast<CallBrInst>(*L);
+      const CallBrInst &RI = cast<CallBrInst>(*R);
+      if (LI.getNumIndirectDests() != RI.getNumIndirectDests()) {
+        if (Complain)
+          Engine.log("callbr # of indirect destinations 
diff er");
+        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 (
diff CallSites(LI, RI, Complain))
+        return true;
+
+      if (TryUnify)
+        tryUnify(LI.getDefaultDest(), RI.getDefaultDest());
+      return false;
+
     } else if (isa<BranchInst>(L)) {
       const BranchInst *LI = cast<BranchInst>(L);
       const BranchInst *RI = cast<BranchInst>(R);


        


More information about the llvm-commits mailing list