This is an archive of the discontinued LLVM Phabricator instance.

[DAG] visitAND - fold (and (any_ext V), c) -> (zero_ext (and (trunc V), c)) if profitable.
ClosedPublic

Authored by RKSimon on Mar 12 2023, 4:28 AM.

Details

Summary

Try to more aggressively narrow masks of extended values.

This is mainly for cases where the mask is trying to zero out any_extended upper bits, assuming we can zext/trunc the values for free.

This catches a few actual missed folds, as well as helps canonicalize a number of other cases which were being caught in isel etc.

Diff Detail

Event Timeline

RKSimon created this revision.Mar 12 2023, 4:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 4:28 AM
RKSimon requested review of this revision.Mar 12 2023, 4:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2023, 4:28 AM
Herald added a subscriber: wdng. · View Herald Transcript
pengfei added inline comments.Mar 12 2023, 5:06 AM
llvm/test/CodeGen/X86/switch-phi-const.ll
95

This doesn't look efficient than decl %ecx.

RKSimon added inline comments.Mar 12 2023, 5:25 AM
llvm/test/CodeGen/X86/switch-phi-const.ll
95

I agree but we always fold mov+dec to lea: https://simd.godbolt.org/z/vvzfe14oc

pengfei accepted this revision.Mar 12 2023, 5:40 AM

X86 tests change looks good.

llvm/test/CodeGen/X86/switch-phi-const.ll
95

Thanks! I see, just notice we also saved a movzbl %dil, %eax. So it's indeed a win.

This revision is now accepted and ready to land.Mar 12 2023, 5:40 AM