This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Improve transforms for `(mul X, Y)` -> `(shl X, log2(Y)`
ClosedPublic

Authored by goldstein.w.n on Mar 17 2023, 7:04 PM.

Details

Summary

Using the more robust log2 search allows us to fold more cases (same
logic as exists for idiv/irem).

Diff Detail

Event Timeline

goldstein.w.n created this revision.Mar 17 2023, 7:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 7:04 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Mar 17 2023, 7:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 7:04 PM
nikic added inline comments.Mar 18 2023, 4:53 AM
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
489

We should preserve the nuw flag here: https://alive2.llvm.org/ce/z/YkwtoD

We can't preserve nsw due to the INT_MIN edge case: https://alive2.llvm.org/ce/z/HTaC3b

Propegate nuw flag

goldstein.w.n marked an inline comment as done.Mar 18 2023, 2:01 PM
goldstein.w.n added inline comments.
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
489

We should preserve the nuw flag here: https://alive2.llvm.org/ce/z/YkwtoD

We can't preserve nsw due to the INT_MIN edge case: https://alive2.llvm.org/ce/z/HTaC3b

Also added test this.

nikic accepted this revision.Mar 18 2023, 2:18 PM

LGTM

This revision is now accepted and ready to land.Mar 18 2023, 2:18 PM
goldstein.w.n marked an inline comment as done.

Rebase

This revision was landed with ongoing or failed builds.Apr 7 2023, 12:58 PM
This revision was automatically updated to reflect the committed changes.