This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Relax cttz/ctlz with select on zero
ClosedPublic

Authored by nikic on Dec 17 2018, 1:23 PM.

Details

Summary

The cttz/ctlz intrinsics have a parameter specifying whether the result is undefined for zero. cttz(x, false) can be relaxed to cttz(x, true) if x is known non-zero, and in fact such an optimization is already performed. However, this currently doesn't work if x is non-zero as a result of a select rather than an explicit branch. This patch adds handling for this case, thus allowing x != 0 ? cttz(x, false) : y to simplify to x != 0 ? cttz(x, true) : y.

Diff Detail

Event Timeline

nikic created this revision.Dec 17 2018, 1:23 PM
spatel accepted this revision.Jan 4 2019, 10:02 AM

LGTM - please modify or add a test to use vector types, so we have some coverage for that possibility.

This revision is now accepted and ready to land.Jan 4 2019, 10:02 AM
This revision was automatically updated to reflect the committed changes.