Page MenuHomePhabricator

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

Authored by goldstein.w.n on Fri, Mar 17, 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

Unit TestsFailed

TimeTest
110 msx64 debian > Flang.Driver::code-gen-rv64.f90
Script: -- : 'RUN: at line 5'; rm -f /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o

Event Timeline

goldstein.w.n created this revision.Fri, Mar 17, 7:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Mar 17, 7:04 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Fri, Mar 17, 7:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Mar 17, 7:04 PM
nikic added inline comments.Sat, Mar 18, 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.Sat, Mar 18, 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.Sat, Mar 18, 2:18 PM

LGTM

This revision is now accepted and ready to land.Sat, Mar 18, 2:18 PM