This is an archive of the discontinued LLVM Phabricator instance.

[X86] Attempt to fold EFLAGS into X86ISD::ADD/SUB ops
ClosedPublic

Authored by RKSimon on May 15 2022, 2:10 PM.

Details

Summary

We already use combineAddOrSubToADCOrSBB to fold extended EFLAGS results into ISD::ADD/SUB ops as X86ISD::ADC/SBB carry ops.

This patch extends this to also fold EFLAGS results with X86ISD::ADD/SUB ops

Diff Detail

Event Timeline

RKSimon created this revision.May 15 2022, 2:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 2:10 PM
RKSimon requested review of this revision.May 15 2022, 2:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2022, 2:10 PM
chfast accepted this revision.May 16 2022, 12:32 AM

Looks very nice, thanks.

This revision is now accepted and ready to land.May 16 2022, 12:32 AM
craig.topper added inline comments.May 16 2022, 12:56 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
52615

Since the ADD/SUB that is being replaced has flag users that might use the carry flag. Do all of the combines in combineAddOrSubToADCOrSBB produce the same value for the carry flag as the original ADD/SUB.

I'm not sure this one does

-1 + SETAE --> -1 + (!CF) --> CF ? -1 : 0 --> SBB %eax, %eax

But I admit I'm having a hard time thinking about it.

I can initially limit this to cases that create SBB $0, %REG patterns if you think it safer?

RKSimon updated this revision to Diff 429662.May 16 2022, 2:47 AM

Restrict ADC/SBB folds to cases where the second op will be zero.

RKSimon requested review of this revision.May 16 2022, 2:48 AM
This revision is now accepted and ready to land.May 16 2022, 11:54 PM
This revision was landed with ongoing or failed builds.May 17 2022, 2:59 AM
This revision was automatically updated to reflect the committed changes.