This is an archive of the discontinued LLVM Phabricator instance.

[x86] make select lowering using SBB hack more flexible
ClosedPublic

Authored by spatel on Jan 6 2022, 12:37 PM.

Details

Summary

select (X != 0), -1, Y --> 0 - X; or (sbb), Y
select (X != 0), Y, -1 --> X - 1; or (sbb), Y

We already had these x86 carry-flag transforms, but one was over-specified to handle a "0" select arm. That's just a special-case of the more general pattern (the 'or' will be deleted if Y is zero).

This is part of solving #53006, but it misses that example because some other combine has already converted that exact pattern into math ops.

Diff Detail

Event Timeline

spatel created this revision.Jan 6 2022, 12:37 PM
spatel requested review of this revision.Jan 6 2022, 12:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 6 2022, 12:37 PM
craig.topper added inline comments.Jan 6 2022, 6:47 PM
llvm/lib/Target/X86/X86ISelLowering.cpp
24565

Might be able to use X86ISD::SETCC_CARRY? Though SBB with identical source is only recognized as a special case on AMD CPUs last I knew.

spatel added inline comments.Jan 7 2022, 4:04 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
24565

Aha - I always forget that we have that node. Yes, we should be using that...something like this:

SDValue Res = DAG.getNode(X86ISD::SETCC_CARRY, DL, VT,
                   DAG.getTargetConstant(X86::COND_B, DL, MVT::i8),
                   Cmp.getValue(1));

That's going to cause a few more test diffs though, so I'd prefer to make it another patch.

spatel updated this revision to Diff 398096.Jan 7 2022, 4:05 AM

Updated TODO comment to mention SETCC_CARRY.

This revision is now accepted and ready to land.Jan 7 2022, 9:25 AM
This revision was landed with ongoing or failed builds.Jan 7 2022, 10:24 AM
This revision was automatically updated to reflect the committed changes.