This is an archive of the discontinued LLVM Phabricator instance.

[llvm-diff] Fix false alarm on PHI node
Needs RevisionPublic

Authored by Nuullll on Jun 16 2022, 7:42 PM.

Details

Summary

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@intel.com>

Diff Detail

Event Timeline

Nuullll created this revision.Jun 16 2022, 7:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 7:42 PM
Nuullll requested review of this revision.Jun 16 2022, 7:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2022, 7:42 PM
Nuullll updated this revision to Diff 437778.Jun 16 2022, 7:48 PM
fhahn added a subscriber: fhahn.Jun 20 2022, 2:21 AM

Thanks for the patch. Some comments inline

llvm/test/tools/llvm-diff/phinode-1.ll
2

I think this also needs a FileCheck call to check that llvm-diff handles the case as expected? Please see other tests like llvm/test/tools/llvm-diff/anon-func.ll for example.

13

might be good to also add a test case with operands of the phi flipped.

llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
594

Does this handle cycles in phi nodes correctly? It would be good to at least have a couple of tests with cycles.

Nuullll added inline comments.Jun 23 2022, 6:47 PM
llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
594

Thanks a lot for reviewing!
This actually is causing infinite recursions for cycled phi nodes.
I'll reconsider the algorithm.

fhahn requested changes to this revision.Jun 24 2022, 12:25 AM
This revision now requires changes to proceed.Jun 24 2022, 12:25 AM