This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] improve demanded bits analysis of left-shifted operand
ClosedPublic

Authored by spatel on Apr 28 2021, 2:29 PM.

Details

Summary

If we don't demand high bits, then we also don't care about those high bits of a left-shift operand regardless of shift amount.
I noticed the sext/trunc pattern in a motivating example.
It seems like there should be a low-bits with right-shift sibling, but I haven't looked at that yet.

https://alive2.llvm.org/ce/z/JuS6jc
https://rise4fun.com/Alive/Trm (not sure how to use 'width' with Alive1)
https://alive2.llvm.org/ce/z/gRadbF

Diff Detail

Event Timeline

spatel created this revision.Apr 28 2021, 2:29 PM
spatel requested review of this revision.Apr 28 2021, 2:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2021, 2:29 PM
spatel added inline comments.Apr 28 2021, 2:36 PM
llvm/test/Transforms/InstCombine/rotate.ll
446–447

The extra trunc now matches the test below this one. We're using MaskedValueIsZero() to match the funnel/rotate operand, so it's not clear how to tell if they start at the same value in this case. CSE should take care of it.

nikic accepted this revision.Apr 29 2021, 1:17 PM

LGTM

This revision is now accepted and ready to land.Apr 29 2021, 1:17 PM

For reference, this patch missed a requirement: we have to drop poison flags on the shl as part of the transform.
Otherwise, we can miscompile as shown in:
https://llvm.org/PR50341
Should be fixed with:
e82db87fb102