This is an archive of the discontinued LLVM Phabricator instance.

[X86] Turn X86ISD::AND nodes that have no flag users back into ISD::AND just before isel to enable test instruction matching
ClosedPublic

Authored by craig.topper on Jan 31 2018, 1:52 PM.

Details

Summary

EmitTest sometimes creates X86ISD::AND specifically to hide the AND from DAG combine. But this prevents isel patterns that look for (cmp (and X, Y), 0) from being able to see it. So we end up with an AND and a TEST. The TEST gets removed by compare instruction optimization during the peephole pass.

This patch attempts to fix this by converting X86ISD::AND with no flag users back into ISD::AND during the DAG preprocessing just before isel.

In order to do this correctly I had to make the X86ISD::AND node created by EmitTest in this case really have a flag output. Which arguably it should have had anyway so that the number of operands would be consistent for the opcode in all cases. Then I had to modify the ReplaceAllUsesWith to understand that we might be looking at an instruction with 2 outputs. Though in this case there are no uses to replace since we just created the node, but that's what the code did before so I just made it keep working.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Jan 31 2018, 1:52 PM
RKSimon accepted this revision.Feb 1 2018, 6:13 AM

LGTM

This revision is now accepted and ready to land.Feb 1 2018, 6:13 AM
This revision was automatically updated to reflect the committed changes.