This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] cttz(zext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true' (PR50172)
ClosedPublic

Authored by xbolva00 on Apr 29 2021, 3:25 PM.

Details

Summary

Zext doesn't change the number of trailing zeros, so narrow cttz(zext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true'.

Proofs:
https://alive2.llvm.org/ce/z/o2dnjY

Solves https://bugs.llvm.org/show_bug.cgi?id=50172

Diff Detail

Event Timeline

xbolva00 created this revision.Apr 29 2021, 3:25 PM
xbolva00 requested review of this revision.Apr 29 2021, 3:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2021, 3:25 PM
xbolva00 updated this revision to Diff 341679.Apr 29 2021, 3:30 PM
xbolva00 updated this revision to Diff 341680.Apr 29 2021, 3:32 PM

Added tests

llvm/test/Transforms/InstCombine/cttz.ll
8

Enough tests?

TODO: cttz(sext(x)) -> zext(cttz(x))

xbolva00 edited the summary of this revision. (Show Details)Apr 29 2021, 4:02 PM
xbolva00 updated this revision to Diff 341697.Apr 29 2021, 4:09 PM

Handle also cttz(sext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true'

xbolva00 updated this revision to Diff 341698.Apr 29 2021, 4:10 PM
xbolva00 retitled this revision from [InstCombine] cttz(zext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true' (PR50172) to [InstCombine] cttz(z/sext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true' (PR50172).
xbolva00 edited the summary of this revision. (Show Details)

Feel free to add tests as preliminary steps - no pre-commit review needed for that.

It would be more flexible to make a "sext -> zext" transform as an independent fold - it doesn't require that zero is undef?
https://alive2.llvm.org/ce/z/kZ7BR6

@xbolva00 Please don't forget to generate the diffs with context

Thanks for feedback, sext case will be in second patch.

xbolva00 retitled this revision from [InstCombine] cttz(z/sext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true' (PR50172) to [InstCombine] cttz(zext(x)) -> zext(cttz(x)) if the 'ZeroIsUndef' parameter is 'true' (PR50172).Apr 30 2021, 3:44 PM
xbolva00 edited the summary of this revision. (Show Details)
xbolva00 updated this revision to Diff 342077.Apr 30 2021, 4:08 PM

Precommited tests. Rebased.

X86 backend patch landed https://reviews.llvm.org/D101662 to avoid regressions.

xbolva00 updated this revision to Diff 342144.May 1 2021, 7:14 AM

Fixed typo in test name.

xbolva00 updated this revision to Diff 342146.May 1 2021, 7:14 AM
xbolva00 updated this revision to Diff 342149.May 1 2021, 7:18 AM
spatel accepted this revision.May 3 2021, 5:27 AM

LGTM

This revision is now accepted and ready to land.May 3 2021, 5:27 AM