This is an archive of the discontinued LLVM Phabricator instance.

[TargetLowering] Replace Log2_32_Ceil with Log2_32 in SimplifySetCC ctpop combine.
ClosedPublic

Authored by craig.topper on Oct 14 2020, 10:55 AM.

Details

Summary

This combine can look through (trunc (ctpop X)). When doing this
it tries to make sure the trunc doesn't lose any information
from the ctpop. It does this by checking that the truncated type
has more bits that Log2_32_Ceil of the ctpop type. The Ceil is
unnecessary and pessimizes non-power of 2 types.

For example, ctpop of i256 requires 9 bits to represent the max
value of 256. But ctpop of i255 only requires 8 bits to represent
the max result of 255. Log2_32_Ceil of 256 and 255 both return 8
while Log2_32 returns 8 for 256 and 7 for 255

The code with popcnt enabled is a regression for this test case,
but it does match what already happens with i256 truncated to i9.
Since power of 2 is more likely, I don't think it should block
this change.

Diff Detail

Event Timeline

craig.topper created this revision.Oct 14 2020, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2020, 10:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
craig.topper requested review of this revision.Oct 14 2020, 10:55 AM
spatel accepted this revision.Oct 14 2020, 11:35 AM

LGTM - thanks for explaining it.

llvm/test/CodeGen/X86/ctpop-combine.ll
164–165

Add 'nounwind' attribute to avoid cfi noise?

This revision is now accepted and ready to land.Oct 14 2020, 11:35 AM