This is an archive of the discontinued LLVM Phabricator instance.

Improve mul combine for negative multiplayer (2^c - 1)
ClosedPublic

Authored by m_zuckerman on Jan 3 2017, 6:58 AM.

Details

Summary

This function improves the mul instruction combine function (combineMul)
by adding new layer of logic.
In this patch, we are adding the ability to fold (mul x, -((1 << c) -1))
or (mul x, -((1 << c) +1)) into (neg(X << c) -x) or (neg((x << c) + x) respective.

Diff Detail

Event Timeline

m_zuckerman updated this revision to Diff 82883.Jan 3 2017, 6:58 AM
m_zuckerman retitled this revision from to Improve mul combine for negative multiplayer (2^c - 1).
m_zuckerman updated this object.
igorb added inline comments.Jan 10 2017, 4:57 AM
lib/Target/X86/X86ISelLowering.cpp
28880

does NumSign * SignMulAmt == MulAmt, or i missing something ?

28888

this is common code for the both cases . can we put it after if/else ?
if (NumSign == -1 && NewMul) ...

test/CodeGen/X86/imul.ll
175

Sorry, i can't understand the test output. Could you please auto-generate the CHECKS ?

m_zuckerman marked 2 inline comments as done.
m_zuckerman marked an inline comment as done.Jan 15 2017, 6:01 AM
m_zuckerman added inline comments.
lib/Target/X86/X86ISelLowering.cpp
28880

Yes mine is sext will the MulAmt is zext

igorb accepted this revision.Jan 17 2017, 12:55 AM

LGTM

This revision is now accepted and ready to land.Jan 17 2017, 12:55 AM
This revision was automatically updated to reflect the committed changes.

How did this get merged without any performance data? It isn't obvious this is a good idea.

Hi Eli,

We tested the patch with internal performance tests.
If you have test/suite/benchmark that my patch bring down, please share them with me.

Regards,
Michael Zuckerman

I don't have any specific issue with this patch (I don't do x86 benchmarking), but it would be a good idea to have some sort of record of what this is actually improving; if someone revisits this code in the future, they won't have access to Intel-internal benchmark numbers.