Page MenuHomePhabricator

Add a test case to show isKnownNonZero() returns correctly; NFC
ClosedPublic

Authored by junbuml on Feb 4 2016, 4:59 PM.

Details

Summary

Added a test case just to make sure that isKnownNonZero() returns false
when we cannot guarantee that a ConstantExpr is a non-zero constant.

Diff Detail

Repository
rL LLVM

Event Timeline

junbuml updated this revision to Diff 46980.Feb 4 2016, 4:59 PM
junbuml retitled this revision from to [ValueTracking] Use Constant::isZeroValue() in isKnownZero().
junbuml updated this object.
junbuml added reviewers: sanjoy, mcrosier, majnemer.
junbuml added a subscriber: llvm-commits.

Jun,

This makes sense to me. But I'm curious if you've seen any changes with this because it doesn't look to be functionally identical, due to the extra floating point checking done in isZeroValue. While you're here, it would be nice to fix the comment for the function to mention the constants.

This makes sense to me. But I'm curious if you've seen any changes with this because it doesn't look to be functionally identical, due to the extra floating point checking done in isZeroValue. While you're here, it would be nice to fix the comment for the function to mention the constants.

I am sending this out to get any early feedback. Since this is not a NFC, I need to check performance. This is also missing test cases that I will add soon.

nlewycky requested changes to this revision.Feb 5 2016, 10:29 AM
nlewycky added a reviewer: nlewycky.
nlewycky added a subscriber: nlewycky.

What about a ConstantExpr like "and(ptrtoint(@global), 32)"? We don't know the 5th bit of the address of @global, so C->isZeroValue() returns false (since we don't know it's zero), but isKnownNonZero must also return false (since we don't know it's non-zero). With your patch, we would incorrectly return true.

You are replacing "is known to be non-zero" with "is not known to be zero" which are not quite the same thing for all Constants. Please send out a patch which adds a testcase that would fail if someone were to propose this change in the future.

This revision now requires changes to proceed.Feb 5 2016, 10:29 AM
junbuml updated this revision to Diff 47648.Feb 11 2016, 8:03 AM
junbuml retitled this revision from [ValueTracking] Use Constant::isZeroValue() in isKnownZero() to Add a test case to show isKnownNonZero() returns correctly; NFC.
junbuml updated this object.
junbuml edited edge metadata.

Based on Nick's comment, I just added a test case to prevent any similar changes in future.
Thanks Nick for the comment.

mcrosier accepted this revision.Feb 11 2016, 9:04 AM
mcrosier edited edge metadata.

LGTM, with minor nits.

test/Transforms/InstSimplify/compare.ll
336 ↗(On Diff #47648)

Please drop "expect to".

Also, please maximize 80-column.

junbuml updated this revision to Diff 47666.Feb 11 2016, 9:14 AM
junbuml edited edge metadata.

Addressed Chad's comment.

This revision was automatically updated to reflect the committed changes.