This is an archive of the discontinued LLVM Phabricator instance.

[X86] Fold X86ISD::SBB(ISD::SUB(X,Y),0) -> X86ISD::SBB(X,Y) (PR25858)
ClosedPublic

Authored by RKSimon on Jan 24 2019, 10:52 AM.

Details

Summary

We often generate X86ISD::SBB(X, 0) for carry flag arithmetic.

I had tried to create test cases for the ADC equivalent (which often uses the same pattern) but haven't managed to find anything yet.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Jan 24 2019, 10:52 AM
craig.topper added inline comments.Jan 24 2019, 12:25 PM
lib/Target/X86/X86ISelLowering.cpp
40510 ↗(On Diff #183339)

This is only valid if the flag result of the SBB is dead. If the sub(X,Y) had a borrow, that information was silently dropped. The SBB output flag should only be calculating the borrow from the result of the subtract minus the C flag. By folding them it would calculate the C flag based on the combined subtraction.

This is the same reason DAGCombiner::visitADDCARRYLike has a check that the ADDCARRY flag result isn't used.

RKSimon planned changes to this revision.Jan 24 2019, 12:53 PM
RKSimon marked an inline comment as done.
RKSimon added inline comments.
lib/Target/X86/X86ISelLowering.cpp
40510 ↗(On Diff #183339)

LOL - I realised that walking home. I'll take another look.

RKSimon updated this revision to Diff 183499.Jan 25 2019, 2:24 AM

Limit the combine to cases where we don't use the output overflow flag

@craig.topper Does this look ok now?

This revision is now accepted and ready to land.Jan 26 2019, 10:41 AM
This revision was automatically updated to reflect the committed changes.