This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Pull out logic for detecting if `(add X, Y)` is non-zero; NFC
ClosedPublic

Authored by goldstein.w.n on Apr 27 2023, 11:16 PM.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Apr 27 2023, 11:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 11:16 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Apr 27 2023, 11:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 11:16 PM
nikic added inline comments.Apr 28 2023, 5:47 AM
llvm/lib/Analysis/ValueTracking.cpp
2839–2840

Can we directly return isNonZeroAdd?

goldstein.w.n added inline comments.Apr 28 2023, 8:01 AM
llvm/lib/Analysis/ValueTracking.cpp
2839–2840

No, we actually benefit from compute known bits. Take the following. X[0] == 0 and Y[0] == 1. The result will be odd (from computeknownbits) so non-zero, but we don't get that here (would need to replicate computeknownnbits to do that).

nikic added inline comments.Apr 28 2023, 8:04 AM
llvm/lib/Analysis/ValueTracking.cpp
2839–2840

Okay, can we then just call KnownBits::computeForAddSub(...).isNonZero() at the end? After all we already calculated known bits for both operands, so no point in calculating them again via the generic code.

Make it so that isNonZeroAdd can be used as final impl for Add case

goldstein.w.n marked 2 inline comments as done.Apr 29 2023, 9:12 AM
nikic accepted this revision.Apr 29 2023, 9:50 AM

LGTM

This revision is now accepted and ready to land.Apr 29 2023, 9:50 AM