This is an archive of the discontinued LLVM Phabricator instance.

Make G_PTR_ADD pattern matcher non-commutative.
ClosedPublic

Authored by mysterymath on Nov 26 2021, 12:02 PM.

Details

Summary

G_PTR_ADD takes arguments of two different types, so it probably shouldn't be
considered commutative just on that basis. A recent G_PTR_ADD reassociation
optimization (https://reviews.llvm.org/D109528) can emit erroneous code if the
pattern matcher commutes the arguments; this can happen when the base pointer
was created by G_INTTOPTR of a G_CONSTANT and the offset register is variable.

This was discovered on the llvm-mos fork, but I added a failing test case that
should apply to AArch64 (and more generally).

Also, this is my first change to LLVM proper, so please let me know if there's
anything amiss with my interpretation of the CR process. Take care!

Diff Detail

Event Timeline

mysterymath created this revision.Nov 26 2021, 12:02 PM
mysterymath requested review of this revision.Nov 26 2021, 12:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 26 2021, 12:02 PM
aemerson accepted this revision.Nov 30 2021, 12:29 AM

LGTM, thanks.

This revision is now accepted and ready to land.Nov 30 2021, 12:29 AM

I should mention that I don't have commit access. Would someone mind committing this when they get the chance?

This revision was automatically updated to reflect the committed changes.