This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add XOR(X, MIN_SIGNED_VALUE) -> ADD(X, MIN_SIGNED_VALUE) isel patterns (PR52267)
ClosedPublic

Authored by RKSimon on Apr 4 2022, 9:11 AM.

Diff Detail

Event Timeline

RKSimon created this revision.Apr 4 2022, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 9:11 AM
RKSimon requested review of this revision.Apr 4 2022, 9:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 4 2022, 9:11 AM
craig.topper added inline comments.Apr 4 2022, 9:41 AM
llvm/lib/Target/X86/X86InstrCompiler.td
1521

I'm not sure the "If safe" is needed here. I think this was copied from or_is_add where "safe" meant checking known bits. Here you explicitly wrote min_signed_value so there's nothing additional to check.

1525

Drop curly braces?

You could even write

ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1));
return CN && CN->isMinSignedValue()
RKSimon updated this revision to Diff 420226.Apr 4 2022, 10:20 AM

address feedback

craig.topper added inline comments.Apr 4 2022, 10:28 AM
llvm/lib/Target/X86/X86InstrCompiler.td
1529

It occurs to me you could avoid the AddedComplexity by writing

def : Pat<(xor GR8:$src1, 128),
          (ADD8ri GR8:$src1, 128)>;
def : Pat<(xor GR16:$src1, 32768),
          (ADD16ri GR16:$src1, 32768)>;
def : Pat<(xor GR32:$src1, 2147483648),
          (ADD32ri GR32:$src1, 2147483648)>;
craig.topper added inline comments.Apr 4 2022, 11:03 AM
llvm/lib/Target/X86/X86InstrCompiler.td
1529

Those might need to be negative constants.

RKSimon updated this revision to Diff 420258.Apr 4 2022, 11:40 AM

remove PatFrags

This revision is now accepted and ready to land.Apr 4 2022, 11:44 AM
This revision was landed with ongoing or failed builds.Apr 4 2022, 11:48 AM
This revision was automatically updated to reflect the committed changes.