This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Make i32 ISD::ABS Legal instead of pattern matching during isel.
AbandonedPublic

Authored by craig.topper on Feb 20 2022, 11:59 PM.

Details

Summary

Instead of matching (sra (X, size(X)-1); sub (xor (X, Y), Y))
during isel, make ISD::ABS Legal and use a regular isel pattern.

Also add new pseudo instructions for NABS to avoid creating a negate
after the ABS pseudo expansion. NABS is no longer expanded by DAGCombiner
to (sra (X, size(X)-1); sub (Y, xor (X, Y)) due to ABS being legal.
The new codegen looks like what gcc generates for NABS.

This is a followup from D119171.

Diff Detail

Event Timeline

craig.topper created this revision.Feb 20 2022, 11:59 PM
craig.topper requested review of this revision.Feb 20 2022, 11:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2022, 11:59 PM

Hi @craig.topper, I'll be honest I haven't reviewed the code changes, but just looking at the tests it's not immediately obvious (to me at least!) what the benefit of this change is? Of course I could be missing something subtle here!

llvm/test/CodeGen/ARM/iabs.ll
50

I tested this out without your patch and I got this:

eor     r1, r0, r0, asr #31
rsb     r0, r1, r0, asr #31
bx      lr

which has the same number of instructions, but without any control flow.

llvm/test/CodeGen/Thumb2/abs.ll
44

It feels like this is actually now worse than before due to the presence of hardware control flow? Previously the eor.w and rsb instructions had no dependency on flags and also didn't set any.

Hi @craig.topper, I'll be honest I haven't reviewed the code changes, but just looking at the tests it's not immediately obvious (to me at least!) what the benefit of this change is? Of course I could be missing something subtle here!

I don't understand it either. My goal was to remove the ABS matching code in ARMISelDAGToDAG.cpp which pre-dated the existence of the ISD::ABS node. After that I figured if the generated code for ABS using predicated RSB was better than the default expansion, then NABS should do the same thing using a different predicate.

Ping. Are there other reviews who can help understand if what is being done for ABS makes sense to extend to NABS?

Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2022, 4:55 PM
david-arm resigned from this revision.Feb 22 2023, 3:58 AM

This patch hasn't moved for a long time. Trying to clean up my review list in Phabricator!

craig.topper abandoned this revision.Feb 22 2023, 8:54 AM