This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] C - cttz(X) => ctlz(X) if C is bitwidth
AbandonedPublic

Authored by deadalnix on Jan 3 2023, 6:12 PM.

Details

Summary

Also do its counterpart C - ctlz(X) => cttz(X) if C is bitwidth .

Diff Detail

Event Timeline

deadalnix created this revision.Jan 3 2023, 6:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 6:12 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
deadalnix requested review of this revision.Jan 3 2023, 6:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 3 2023, 6:12 PM
nikic added a reviewer: nikic.Jan 4 2023, 1:25 AM
nikic added a subscriber: nikic.

This is missing alive2 proofs.

Are there any tests where C is not the bit width? I didn't spot them.

Won't this only work if only a single bit is set (pow2)?

nikic requested changes to this revision.Jan 4 2023, 2:26 AM

Won't this only work if only a single bit is set (pow2)?

That, and it's off by one (the constant needs to be bitwidth-1, not bitwidth). The right transform would be this: https://alive2.llvm.org/ce/z/v588Fk

This revision now requires changes to proceed.Jan 4 2023, 2:26 AM

Lesson of the day, don't submit patches at 3am. It'll get this sorted out.

deadalnix abandoned this revision.Jan 4 2023, 5:35 AM

Ok, it turns out I'm an idiot and the correct transformation is already done. Sorry everybody.