This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach RISCVCodeGenPrepare to optimize (i64 (and (zext/sext (i32 X), C1)))
ClosedPublic

Authored by craig.topper on Jul 15 2022, 11:14 AM.

Details

Summary

If X is known positive by a dominating condition, we can fill in
ones into the upper bits of C1 if that would allow it to become an
simm12 allowing the use of ANDI.

This pattern often occurs in unrolled loops where the induction
variable has been widened.

To get the best benefit from this, I had to move the pass above
ConstantHoisting which is in addIRPasses. Otherwise the AND constant
is often hoisted away from the AND.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 15 2022, 11:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 11:14 AM
craig.topper requested review of this revision.Jul 15 2022, 11:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 11:14 AM
asb accepted this revision.Jul 17 2022, 8:11 AM

LGTM - thanks!

llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp
74

Changes to optimizeZExt should really be a separate patch

This revision is now accepted and ready to land.Jul 17 2022, 8:11 AM
This revision was landed with ongoing or failed builds.Jul 17 2022, 11:06 AM
This revision was automatically updated to reflect the committed changes.