This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] try to avoid multiply for X*Y==0
ClosedPublic

Authored by spatel on Jan 5 2023, 1:22 PM.

Details

Summary

Forking this off from D140850 -
https://alive2.llvm.org/ce/z/TgBeK_
https://alive2.llvm.org/ce/z/STVD7d

We could almost justify doing this in IR, but consideration for minsize compiles requires that we only try it in codegen -- the transform is not reversible.

In all other cases, avoiding multiply should be a win because a mul is more expensive than simple/parallelizable compares. AArch even has a trick (assuming that's the correct asm) to keep instruction count even for some types.

Diff Detail

Event Timeline

spatel created this revision.Jan 5 2023, 1:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 1:22 PM
spatel requested review of this revision.Jan 5 2023, 1:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 1:22 PM
goldstein.w.n added inline comments.Jan 5 2023, 2:02 PM
llvm/test/CodeGen/X86/mul-cmp.ll
111

Wow nice!

The proof does not match the transform you are making (https://alive2.llvm.org/ce/z/TgBeK_, aka drop noundef)

nikic accepted this revision.Jan 6 2023, 1:14 AM

LGTM

This revision is now accepted and ready to land.Jan 6 2023, 1:14 AM
dmgreen accepted this revision.Jan 6 2023, 2:22 AM

Sounds OK. Thanks

I think we can save an extra instruction on the i8/i16 cases that use a tst if we fold an and/or into a csel. I'll see if I can put together a patch.

spatel edited the summary of this revision. (Show Details)Jan 6 2023, 4:20 AM
spatel edited the summary of this revision. (Show Details)
spatel added a comment.Jan 6 2023, 4:23 AM

The proof does not match the transform you are making (https://alive2.llvm.org/ce/z/TgBeK_, aka drop noundef)

Thanks - updated links in the description. I had adapted an example with i32 and that was timing out, so I tacked on noundef, but forgot to adjust it later.

This revision was landed with ongoing or failed builds.Jan 6 2023, 6:07 AM
This revision was automatically updated to reflect the committed changes.