This is an archive of the discontinued LLVM Phabricator instance.

[ARM][CGP] Negative constant operand handling
ClosedPublic

Authored by samparker on Nov 1 2018, 1:59 AM.

Details

Summary

While mutating instructions, we sign extended negative constant operands for binary operators that can safely overflow. This was to allow instructions, such as add nuw i8 %a, -2, to still be able to perform a subtraction. However, the code to handle constants doesn't take into consideration that instructions, such as sub nuw i8 -2, %a, require the i8 -2 to be converted into i32 254.

This is a relatively simple fix, but I've taken the time to reorganise the code a bit - mainly that instructions that can be promoted are cached.

Diff Detail

Repository
rL LLVM

Event Timeline

samparker created this revision.Nov 1 2018, 1:59 AM

Had a first look, mostly nits.

lib/Target/ARM/ARMCodeGenPrepare.cpp
247 ↗(On Diff #172096)

typo: it's -> its

481 ↗(On Diff #172096)

Thanks for writing this down! So please forgive my nitpicking here.

483 ↗(On Diff #172096)

The ", as immediate values cause complications" comes a bit out of the blue for me. But I see what you want to say: we need to decide whether to sign or zero extend constants (as otherwise we miscompile).

484 ↗(On Diff #172096)

Can you specify what you mean by "most constants"?

485 ↗(On Diff #172096)

What exactly does "could" mean here?

489 ↗(On Diff #172096)

Same here: couldn't

499 ↗(On Diff #172096)

This is more about style, so feel free to ignore, or see what you exactly want to do with this:
this function IRPromoter::Mutate is really big now. Perhaps (some) different things that we do here can be put in separate helper functions (like this below). I think it could help in making clearer the different "mutate steps" that are performed.

500 ↗(On Diff #172096)

I think this worklist already contains instructions that we're interested in. I guess we don't need to check again.

samparker updated this revision to Diff 172106.Nov 1 2018, 4:27 AM

Thanks Sjoerd.

I've now split the mutation into individual functions and fixed up some of the comments.

SjoerdMeijer accepted this revision.Nov 1 2018, 7:14 AM

Cheers, LGTM!

lib/Target/ARM/ARMCodeGenPrepare.cpp
556 ↗(On Diff #172106)

After the reshuffle, "Then mutate .. " can probably now just be "Mutate .."

584 ↗(On Diff #172106)

Here we start doing the next thing, you could put this in another helper function, so that we have a call sequence something like this:

...
PromoteTree() 
OptimizeTree()     // i.e. this code
TruncateSinks()

in Mutate().

680 ↗(On Diff #172106)

Oh yes, exactly what I was hoping for, this reads very, very nice! :-)

This revision is now accepted and ready to land.Nov 1 2018, 7:14 AM
This revision was automatically updated to reflect the committed changes.
llvm/trunk/test/CodeGen/ARM/arm-cgp-signed-icmps.ll