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

Event Timeline

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

Had a first look, mostly nits.

lib/Target/ARM/ARMCodeGenPrepare.cpp
261–262

typo: it's -> its

530

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

532

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).

533

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

534

What exactly does "could" mean here?

538

Same here: couldn't

548

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.

549

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

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

584

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

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.
test/CodeGen/ARM/arm-cgp-signed-icmps.ll