This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Reassociate sub(x, add(m1, m2)) to sub(sub(x, m1), m2)
ClosedPublic

Authored by dmgreen on Feb 2 2023, 12:41 AM.

Details

Summary

The mid end will reassociate sub(sub(x, m1), m2) to sub(x, add(m1, m2)). This reassociates it back to allow the creation of more mls instructions.

Diff Detail

Event Timeline

dmgreen created this revision.Feb 2 2023, 12:41 AM
dmgreen requested review of this revision.Feb 2 2023, 12:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2023, 12:41 AM

The patch looks good to me, but I was just wondering if another approach would be to just match the sub(x, add(m1, m2)). pattern as mls, or is this easier/better?

The patch looks good to me, but I was just wondering if another approach would be to just match the sub(x, add(m1, m2)). pattern as mls, or is this easier/better?

Thats for taking a look. That might be an option, but it would need to match sub(x, add(mul(a,b), mul(c,d))) to two msub(msub(x, a, b), c, d) for all the different types of mls. I think it is probably simpler to go the un-reassociate route.

fhahn accepted this revision.Feb 9 2023, 3:35 AM

LGTM, thanks! Given @dmgreen's point about the number of patterns that would be required the current patch seems like a more general solution.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17717

It might be good to use the same names here as in the comment above, i.e. m1 and m2?

This revision is now accepted and ready to land.Feb 9 2023, 3:35 AM

Yeah, makes sense, cheers. LGTM too

This revision was landed with ongoing or failed builds.Feb 10 2023, 10:09 AM
This revision was automatically updated to reflect the committed changes.

This caused hangs when compiling some source files from ffmpeg, libvpx and libaom. One repro is available at https://martin.st/temp/adxenc.c, triggered with clang -target aarch64-w64-mingw32 -c -O2 adxenc.c -w.

I’ll push a revert soon.

Thanks for the report. I had somehow missed vector constants even though scalars were being correctly handled. I thought I had added tests for them but apparently not.