[PATCH] D128024: [llvm-diff] Fix false alarm on PHI node

Yilong Guo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 19:42:09 PDT 2022


Nuullll created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
Nuullll requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This addresses https://github.com/llvm/llvm-project/issues/56076

llvm-diff was reporting a false alarm on the `%res` PHI node of the following module, comparing with itself by running `llvm-diff a.ll a.ll`:

  define double @foo() {
  entry:
    br i1 true, label %else, label %exit
  
  else:
    %0 = extractelement <2 x double> zeroinitializer, i64 0
    br label %exit
  
  exit:
    %res = phi double [ 0.000000e+00, %entry ], [ %0, %else ]
    ret double 0.000000e+00
  }

The reason was that:

- The `exit` block is processed before the `else` block.
- When comparing against the PHI node, its operand `%0` is not visited yet. So the fake difference is reported because `%0` is neither mapped nor tentative.

Fixed by calling `diff()` on instructions when checking the operand equivalence.

Signed-off-by: Yilong Guo <yilong.guo at intel.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128024

Files:
  llvm/test/tools/llvm-diff/phinode-1.ll
  llvm/tools/llvm-diff/lib/DifferenceEngine.cpp


Index: llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
===================================================================
--- llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
+++ llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
@@ -590,7 +590,8 @@
       return equivalentAsOperands(cast<Constant>(L), cast<Constant>(R));
 
     if (isa<Instruction>(L))
-      return Values[L] == R || TentativeValues.count(std::make_pair(L, R));
+      return Values[L] == R || TentativeValues.count(std::make_pair(L, R)) ||
+             !diff(cast<Instruction>(L), cast<Instruction>(R), false, false);
 
     if (isa<Argument>(L))
       return Values[L] == R;
Index: llvm/test/tools/llvm-diff/phinode-1.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-diff/phinode-1.ll
@@ -0,0 +1,15 @@
+; Issue: https://github.com/llvm/llvm-project/issues/56076
+; RUN: llvm-diff %s %s
+
+define double @foo() {
+entry:
+  br i1 true, label %else, label %exit
+
+else:
+  %0 = extractelement <2 x double> zeroinitializer, i64 0
+  br label %exit
+
+exit:
+  %res = phi double [ 0.000000e+00, %entry ], [ %0, %else ]
+  ret double 0.000000e+00
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128024.437773.patch
Type: text/x-patch
Size: 1173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220617/7f7f4c4a/attachment.bin>


More information about the llvm-commits mailing list