This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Select G_SELECT cc, t, (G_SUB 0, x) -> CSNEG t, x, cc
ClosedPublic

Authored by paquette on Nov 3 2020, 3:21 PM.

Details

Summary

When we see

%sub = G_SUB 0, %x
%select = G_SELECT %cc, %t, %sub

Fold away the G_SUB by producing

%select = CSNEG %t, %x, cc

Simple IR example: https://godbolt.org/z/K8TEnh

This is valid on both sides of the select, but for now, just handle one side. It may make more sense to handle swapping sides during post-legalizer lowering.

Diff Detail

Event Timeline

paquette created this revision.Nov 3 2020, 3:21 PM
aemerson added inline comments.Nov 12 2020, 10:08 AM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1026

I committed a patch to recognize a negate idiom for G_PTR_ADD in ad376657c1ec4da950d18b37b523585ccd4fc7bb, maybe you can re-use that as a helper, or just copy the MI PatternMatch code since its only a few lines.

paquette added inline comments.Nov 12 2020, 6:03 PM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1026

How about something like D91397?

aemerson added inline comments.Nov 13 2020, 9:05 AM
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
1026

Even better, thanks.

aemerson accepted this revision.Nov 13 2020, 9:05 AM

LGTM once we use the new matcher.

This revision is now accepted and ready to land.Nov 13 2020, 9:05 AM