This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Improve analysis of knownbits from incoming phi edges.
ClosedPublic

Authored by goldstein.w.n on Aug 12 2023, 2:43 PM.

Details

Summary

Use ConstantRange::toKnownBits(ConstantRange::makeExactICmpRegion)
to get the constraints on the incoming phi edge instead of bespoke logic.
This covers a lot more cases.

Proofs: https://alive2.llvm.org/ce/z/gnj4o-

Diff Detail

Event Timeline

goldstein.w.n created this revision.Aug 12 2023, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2023, 2:43 PM
goldstein.w.n requested review of this revision.Aug 12 2023, 2:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 12 2023, 2:43 PM
nikic added inline comments.Aug 12 2023, 3:03 PM
llvm/lib/Analysis/ValueTracking.cpp
1478–1479

Can this code be reduced to ConstantRange::makeExactICmpRegion() + ConstantRange::toKnownBits()?

goldstein.w.n marked an inline comment as done.Aug 12 2023, 6:26 PM
goldstein.w.n added inline comments.
llvm/lib/Analysis/ValueTracking.cpp
1478–1479

Convenient :)

goldstein.w.n marked an inline comment as done.

Nikics suggestion to use ConstantRange codes :)

nikic accepted this revision.Aug 13 2023, 12:15 AM

LGTM

This revision is now accepted and ready to land.Aug 13 2023, 12:15 AM
foad added a comment.Aug 14 2023, 2:14 AM

Just fill in missing cases (TODO) for ugt, uge, sgt, sge,
slt, and sle. These are all in the same spirit as ult/uge, but
each of the other conditions have different constraints.

Update the description?

llvm/lib/Analysis/ValueTracking.cpp
1470

I don't quite understand this TODO, but it seems *maybe* you have implemented what it was suggesting?

goldstein.w.n added inline comments.Aug 14 2023, 9:06 AM
llvm/lib/Analysis/ValueTracking.cpp
1470

I interpretted it to mean use computeKnownBits on RHS instead of only accepting constant RHS.

goldstein.w.n edited the summary of this revision. (Show Details)Aug 14 2023, 9:08 AM

Just fill in missing cases (TODO) for ugt, uge, sgt, sge,
slt, and sle. These are all in the same spirit as ult/uge, but
each of the other conditions have different constraints.

Update the description?

Done :)