This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] More fcmp cases when comparing against negative constants.
ClosedPublic

Authored by paulwalker-arm on Nov 14 2017, 2:55 AM.

Details

Summary

For known positive non-zero value X:

fcmp uge X, -C => true
fcmp ugt X, -C => true
fcmp une X, -C => true
fcmp oeq X, -C => false
fcmp ole X, -C => false
fcmp olt X, -C => false

Patch by Paul Walker.

Diff Detail

Event Timeline

paulwalker-arm created this revision.Nov 14 2017, 2:55 AM
fhahn added a subscriber: fhahn.Nov 15 2017, 6:38 AM

Looks like a straight-forward simplification to me, but it would be good if someone else could have a look too.

spatel edited edge metadata.Nov 27 2017, 8:27 AM

The tests should go under tests/Transforms/InstSimplify since this is handled outside of InstCombine.
I went ahead and added variants of the original tests plus a couple of extras with r319041. The extra tests show at least one possible extension to handle other fcmp predicates. A more general extension might involve a range test rather than using CannotBeOrderedLessThanZero()?

lib/Analysis/InstructionSimplify.cpp
3367–3368

We've already handled isNaN above here? Could assert instead of re-checking that condition or just remove it.

3371

Should add a comment for symmetry:
X > 0 or X > -C

paulwalker-arm edited the summary of this revision. (Show Details)

Broke out the isNegative case into its own block so that more conditions can be handled when it's known the constant is non-zero. Removed my original tests and updated the existing ones to reflect the optimised output.

spatel accepted this revision.Nov 28 2017, 9:27 AM

LGTM.

Please add a 'TODO' comment in the new block of code about extending this. We should have cases for 'UNE' and 'OEQ' predicates too?

This revision is now accepted and ready to land.Nov 28 2017, 9:27 AM

Good point, I'll add the extra conditions along with the TODO.

paulwalker-arm edited the summary of this revision. (Show Details)

Extended to cover une and oeq conditions. Added an assert to protect against unintentional refactoring and a TODO for future improvements.

spatel added inline comments.Nov 29 2017, 7:40 AM
lib/Analysis/InstructionSimplify.cpp
3382

Nit: The assert string would confuse me if we ever hit that because -NaN actually is a (set of) FP value(s).

"Unexpected NaN constant" ?

test/Transforms/InstCombine/cast-int-fcmp-eq-0.ll
334–341

Can you move this and the related tests over to the instsimplify file?

Nit: I'd prefer to change these constants to '-1.0' or whatever they are rather than trying to decode hex values. :)

paulwalker-arm added inline comments.Nov 29 2017, 8:56 AM
test/Transforms/InstCombine/cast-int-fcmp-eq-0.ll
334–341

Will do. Are there any objections to me maintaining the same number of tests within InstSimplify/floating-point-compare.ll but replacing some uses of fabs with uitofp?

spatel added inline comments.Nov 29 2017, 9:09 AM
test/Transforms/InstCombine/cast-int-fcmp-eq-0.ll
334–341

Sounds ok to me. As long we're covering all of the predicates and have some vector tests too, that should keep the fold tested well enough. Might want to vary double/float/half as well just to be sure we hit more types.

Removed three instcombine tests that are either covered by existing instsimplify tests of have equivalent instsimplify tests provided by this patch.

spatel accepted this revision.Nov 30 2017, 10:38 AM

LGTM.

fhahn edited the summary of this revision. (Show Details)Dec 1 2017, 4:33 AM
fhahn closed this revision.Dec 1 2017, 4:34 AM