This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Handle predicates for fold fcmp-of-copysign
AbandonedPublic

Authored by Chenbing.Zheng on Apr 20 2022, 11:37 PM.

Details

Summary

This patch complete predicates for fold fcmp-of-copysign

copysign(non-zero constant, X) <  0.0 --> (bitcast X) <  0
copysign(non-zero constant, X) >  0.0 --> (bitcast X) >  0
copysign(non-zero constant, X) <= 0.0 --> (bitcast X) <= 0
copysign(non-zero constant, X) >= 0.0 --> (bitcast X) >= 0

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2022, 11:37 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Chenbing.Zheng requested review of this revision.Apr 20 2022, 11:37 PM

This is ok as a minimum enhancement, but it's not enough to remove the TODO entirely. We should be able to handle >=, <= too? Ordered vs. unordered does not matter?
Make a 'switch' to map FP predicates to integer predicates?

Chenbing.Zheng retitled this revision from [InstCombine] Handle more predicates for fold fcmp-of-copysign to [InstCombine] Handle predicates for fold fcmp-of-copysign .
Chenbing.Zheng edited the summary of this revision. (Show Details)

address comment

spatel added inline comments.Apr 22 2022, 11:16 AM
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
6762–6763

This is not correct if X is 0.0 (0x00000000).
copysign(1.0, 0.0) <= 0.0 is false
(bitcast 0.0) <= 0 is true

Similarly:
copysign(1.0, 0.0) > 0.0 is true
(bitcast 0.0) > 0 is false

I don't think we can verify copysign with Alive2, so please write a test program to check edge values so we know the transform is always correct.

Also, please pre-commit the baseline tests for each new predicate.

Chenbing.Zheng abandoned this revision.Apr 28 2022, 1:23 AM

Also, please pre-commit the baseline tests for each new predicate.

I have committed other tests. But I have some doubts about this conversion now, so I want to abandon this commit first.