This is an archive of the discontinued LLVM Phabricator instance.

Add test cases showing missed opportunity to use slli.uw or shXadd.uw. NFC
ClosedPublic

Authored by craig.topper on May 27 2022, 10:49 PM.

Details

Summary

The tests here show the codegen for something like this C code.

unsigned diff = ptr1 - ptr2;
return ptr3[diff];

The pointer difference is truncated to 32-bits before being used
again as an index. In SelectionDAG this appears as an AND between
a SRL and a SHL. DAGCombiner will remove the shifts leaving only
an AND. The Mask now has 1,2, or 3 trailing zeros and 31, 30, or 29
leading zeros. We end up falling back to constant materialization
to create this mask.

We could instead use srli followed by slli.uw. Or since
we have an add, we can use srli followed by shXadd.uw.

Diff Detail

Event Timeline

craig.topper created this revision.May 27 2022, 10:49 PM
craig.topper requested review of this revision.May 27 2022, 10:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 27 2022, 10:49 PM
This revision was not accepted when it landed; it landed in state Needs Review.May 29 2022, 6:40 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.