This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] haveNoCommonBitsSet - add assumption cache handling (PR58624)
AbandonedPublic

Authored by RKSimon on Oct 29 2022, 8:06 AM.

Details

Summary

As detailed on Issue #58624, we fail to make use of assume calls when attempting to determine if two values haveNoCommonBitsSet

I've added a basic iterator across the assumption cache, looking for 'no common bits' comparisons - both the basic (lhs & rhs) == 0 and a boolean variant !(lhs & rhs) as comparisons of booleans will get folded.

I had hoped to support vectors as well but it looks like we'd have problems with poison if we try to match through reduction intrinsics: https://alive2.llvm.org/ce/z/Hn3Tnn

If people are happy with this approach, I'll get the test coverage pre-committed to simplify the patch

Diff Detail

Event Timeline

RKSimon created this revision.Oct 29 2022, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2022, 8:06 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
RKSimon requested review of this revision.Oct 29 2022, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2022, 8:06 AM
nikic added a comment.Oct 29 2022, 8:29 AM

Not sure this is useful. The test case from the issue is over-reduced, the actual motivating case would have to handle a dominating condition, not an assume.

llvm/lib/Analysis/ValueTracking.cpp
313

Shouldn't we be lookup up the assumptions for either LHS or RHS here, rather than all of them?

339

You're missing a context validity check. Currently you're using assumes that don't dominate the context instruction.

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3800

Is this useful independently of the assume case?

bcl5980 added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
3800

I guess the answer is no.
The code in llvm::haveNoCommonBitsSet check already exist at:

line 3776: if (SimplifyDemandedInstructionBits(I))
line 3791: if (match(&I, m_c_Xor(m_c_And(m_Not(m_Value(M)), m_Value())

If we add llvm::haveNoCommonBitsSet maybe we can move the code before line 3776 and remove line 3791.

RKSimon planned changes to this revision.Oct 31 2022, 7:20 AM
RKSimon abandoned this revision.Sep 5 2023, 3:05 AM