This is an archive of the discontinued LLVM Phabricator instance.

[x86] Fix an amazing goof in the handling of sub, or, and xor lowering.
ClosedPublic

Authored by chandlerc on Aug 24 2017, 1:01 AM.

Details

Summary

The comment for this code indicated that it should work similar to our
handling of add lowering above: if we see uses of an instruction other
than flag usage and store usage, it tries to avoid the specialized
X86ISD::* nodes that are designed for flag+op modeling.

Problem is, only the add case actually did this. In all the other cases,
the logic was incomplete and inverted. Any time the value was used by
a store, we bailed on the specialized X86ISD node.

Turns out, we have a *ton* of patterns designed around these nodes. We
should actually form them. I fixed the code to match what we do for add,
and it has quite a positive effect just within some of our test cases.
The only thing close to a regression I see is using:

notl %r
testl %r, %r

instead of:

xorl -1, %r

But we can add a pattern or something to fold that back out. The
improvements seem more than worth this.

Unless I'm missing any context here? I just made what seemed like
a "doh!" bug fix, and got ... much more in the way of generated code
changes than I was expecting....

Diff Detail

Repository
rL LLVM

Event Timeline

chandlerc created this revision.Aug 24 2017, 1:01 AM
craig.topper edited edge metadata.Aug 24 2017, 9:22 AM

Curious, what happens if you change it to just

if (UI->getOpcode() != ISD::CopyToReg && UI->getOpcode() != ISD::SETCC)

The "!= ISD::STORE" was added when the INC/DEC support was added to X86ISelDAGToDAG.cpp. Prior to that, ADD just had CopyToReg and SETCC. Sometime even earlier than that ADD was == STORE like SUB/XOR/OR/AND are now.

I don't think the comment above ADD was ever properly updated after != STORE was added.

We can leave the != ISD::STORE. It doesn't seem to have any visible effect right now. So consistency with ISD::ADD is best.

We can leave the != ISD::STORE. It doesn't seem to have any visible effect right now. So consistency with ISD::ADD is best.

Thanks! and thanks for the detailed help! landing...

This revision is now accepted and ready to land.Aug 24 2017, 4:58 PM
This revision was automatically updated to reflect the committed changes.