[llvm] 2975f37 - [llvm-diff] Implement diff of PHI nodes
Bill Wendling via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 22 13:23:19 PST 2021
Author: Bill Wendling
Date: 2021-11-22T13:23:10-08:00
New Revision: 2975f37d8d4ffb8fd2b0950d6851c5fab93b4a19
URL: https://github.com/llvm/llvm-project/commit/2975f37d8d4ffb8fd2b0950d6851c5fab93b4a19
DIFF: https://github.com/llvm/llvm-project/commit/2975f37d8d4ffb8fd2b0950d6851c5fab93b4a19.diff
LOG: [llvm-diff] Implement diff of PHI nodes
Implement diff of PHI nodes
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D114211
Added:
llvm/test/tools/llvm-diff/phinode.ll
Modified:
llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-
diff /phinode.ll b/llvm/test/tools/llvm-
diff /phinode.ll
new file mode 100644
index 0000000000000..d2bcdf3c44559
--- /dev/null
+++ b/llvm/test/tools/llvm-
diff /phinode.ll
@@ -0,0 +1,28 @@
+; RUN: rm -f %t.ll
+; RUN: cat %s | sed -e 's/ 0, %2 / 1, %2 /' > %t.ll
+; RUN: not llvm-
diff %s %t.ll 2>&1 | FileCheck %s
+
+; CHECK: in function foo:
+; CHECK-NEXT: in block %6 / %6:
+; CHECK-NEXT: > %7 = phi i32 [ 1, %2 ], [ -1, %1 ]
+; CHECK-NEXT: > ret i32 %7
+; CHECK-NEXT: < %7 = phi i32 [ 0, %2 ], [ -1, %1 ]
+; CHECK-NEXT: < ret i32 %7
+define i32 @foo(i32 %0) #0 {
+ callbr void asm sideeffect "", "X,~{dirflag},~{fpsr},~{flags}"(i8* blockaddress(@foo, %6))
+ to label %2 [label %6]
+
+2:
+ %3 = icmp eq i32 %0, 0
+ br i1 %3, label %6, label %4
+
+4:
+ br label %5
+
+5:
+ br label %5
+
+6:
+ %7 = phi i32 [ 0, %2 ], [ -1, %1 ]
+ ret i32 %7
+}
diff --git a/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp b/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp
index eb746cd2a8650..4bdefcdc17581 100644
--- a/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp
+++ b/llvm/tools/llvm-
diff /lib/DifferenceEngine.cpp
@@ -269,15 +269,35 @@ class FunctionDifferenceEngine {
} else if (isa<CallInst>(L)) {
return
diff CallSites(cast<CallInst>(*L), cast<CallInst>(*R), Complain);
} else if (isa<PHINode>(L)) {
- // FIXME: implement.
+ const PHINode &LI = cast<PHINode>(*L);
+ const PHINode &RI = cast<PHINode>(*R);
// This is really weird; type uniquing is broken?
- if (L->getType() != R->getType()) {
- if (!L->getType()->isPointerTy() || !R->getType()->isPointerTy()) {
+ if (LI.getType() != RI.getType()) {
+ if (!LI.getType()->isPointerTy() || !RI.getType()->isPointerTy()) {
if (Complain) Engine.log("
diff erent phi types");
return true;
}
}
+
+ if (LI.getNumIncomingValues() != RI.getNumIncomingValues()) {
+ if (Complain)
+ Engine.log("PHI node # of incoming values
diff er");
+ return true;
+ }
+
+ for (unsigned I = 0; I < LI.getNumIncomingValues(); ++I) {
+ if (TryUnify)
+ tryUnify(LI.getIncomingBlock(I), RI.getIncomingBlock(I));
+
+ if (!equivalentAsOperands(LI.getIncomingValue(I),
+ RI.getIncomingValue(I))) {
+ if (Complain)
+ Engine.log("PHI node incoming values
diff er");
+ return true;
+ }
+ }
+
return false;
// Terminators.
More information about the llvm-commits
mailing list