This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Fix recurrence detection to check both PHI operands.
ClosedPublic

Authored by fhahn on Aug 14 2019, 5:43 AM.

Details

Summary

Currently we fail to compute known bits for recurrences where the
first incoming value is the start value of the recurrence.

Instead of exiting the loop when the first incoming value is not
the step of the recurrence, continue to check the second incoming
value.

The original code uses a loop to handle both cases, but incorrectly
exits instead of continuing.

Diff Detail

Event Timeline

fhahn created this revision.Aug 14 2019, 5:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2019, 5:43 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
lebedev.ri added inline comments.Aug 14 2019, 5:50 AM
llvm/test/Transforms/InstCombine/phi-known-bits-operand-order.ll
1

Please use utils/update_test_checks.py and precommit.

fhahn updated this revision to Diff 215345.Aug 15 2019, 1:56 AM

Update test after pre-committing it.

fhahn marked an inline comment as done.Aug 15 2019, 2:01 AM
fhahn added inline comments.
llvm/test/Transforms/InstCombine/phi-known-bits-operand-order.ll
1

Done.
I am a bit torn when it come sousing update_test_checks.py here, as checking everything potentially makes the test slightly more verbose and brittle than necessary. But it is quite convenient.

I know nothing about this code, but the test change appears correct,
and matches what already happens in the second test case.

llvm/lib/Analysis/ValueTracking.cpp
1376
continue; // Check other incoming value
llvm/test/Transforms/InstCombine/phi-known-bits-operand-order.ll
40

I think this should/can be unconditional branch to for.cond11?
It branches on the same condition that brought us here.
Does the fold still happen then?

fhahn updated this revision to Diff 215451.Aug 15 2019, 11:53 AM

Add comment to continue.

fhahn marked 3 inline comments as done.Aug 15 2019, 11:55 AM
fhahn added inline comments.
llvm/test/Transforms/InstCombine/phi-known-bits-operand-order.ll
40

If this branch is unconditional, we get the ult through some other code path (I did not track it down though). My guess is that we evaluate things in a different order.

lebedev.ri accepted this revision.Aug 15 2019, 12:00 PM

Still no clue about this code, but looks plausible.

This revision is now accepted and ready to land.Aug 15 2019, 12:00 PM
This revision was automatically updated to reflect the committed changes.
fhahn marked an inline comment as done.