This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Generalize select (and (x , 0x1) == 0), y, (z ^ y) ) and select (and (x , 0x1) == 0), y, (z | y) ) transforms by removing and-clause
ClosedPublic

Authored by reames on Oct 3 2022, 9:00 AM.

Details

Summary

These transforms were recently added (by me) in D134881. Looking at the code again, I realized we don't need the (and x, 0x1) portion of the pattern, we just need to know that the result of that sub-tree is either 0 or 1. Checking for this directly allows us to match slightly more broadly. The test changes are zext i1 arguments, but this could also kick in for e.g. shifts of high bits, or any other source of known bits.

As an aside, the tests reveal some odd inconsistencies in canonicalization existing in tree. I am not planning to pursue those, just noting that it's quite odd that xor_select_all_zeros_i64 gets recognized, but xor_select_all_zeros_i32 (on RV32 even) doesn't.

Diff Detail

Event Timeline

reames created this revision.Oct 3 2022, 9:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 9:01 AM
reames requested review of this revision.Oct 3 2022, 9:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 3 2022, 9:01 AM
This revision is now accepted and ready to land.Oct 3 2022, 12:33 PM