This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Optimize (add (mul r, c0), c1)
ClosedPublic

Authored by benshi001 on Oct 5 2021, 5:44 AM.

Details

Summary
Optimize (add (mul x, c0), c1) ->
         (add (mul (add x, c1/c0+1), c0), c1%c0-c0),
if c1/c0+1 and c1%c0-c0 are simm12, while c1 is not.

Optimize (add (mul x, c0), c1) ->
         (add (mul (add x, c1/c0-1), c0), c1%c0+c0),
if c1/c0-1 and c1%c0+c0 are simm12, while c1 is not.

Diff Detail

Event Timeline

benshi001 created this revision.Oct 5 2021, 5:44 AM
benshi001 requested review of this revision.Oct 5 2021, 5:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 5:44 AM
benshi001 updated this revision to Diff 377222.Oct 5 2021, 7:01 AM
benshi001 updated this revision to Diff 379580.Oct 13 2021, 6:55 PM
benshi001 added inline comments.Oct 13 2021, 7:37 PM
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6490

Repeated comments are removed.

asb added a comment.Nov 2 2021, 7:53 AM

I've suggested a slight tweak to the explanatory comments.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
6443

"A special corner case that should be excluded is when ..., which will lead to an infinite loop in DAGCombine if transformed." would read more clearly (same for other instances below).

benshi001 updated this revision to Diff 384298.Nov 2 2021, 6:37 PM
benshi001 marked an inline comment as done.
asb accepted this revision.Nov 5 2021, 4:23 AM

I think this is correct. I'd certainly appreciate another pair of eyes confirming they agree though!

This revision is now accepted and ready to land.Nov 5 2021, 4:23 AM

ping ... Can this patch be landed ?

craig.topper accepted this revision.Nov 7 2021, 6:05 PM
This revision was automatically updated to reflect the committed changes.