This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Add tests for binops with conditions/assume constraints
ClosedPublic

Authored by goldstein.w.n on Jan 2 2023, 11:20 AM.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jan 2 2023, 11:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2023, 11:20 AM
goldstein.w.n requested review of this revision.Jan 2 2023, 11:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 2 2023, 11:20 AM
goldstein.w.n edited the summary of this revision. (Show Details)Jan 2 2023, 11:27 AM
goldstein.w.n added reviewers: nikic, majnemer.
goldstein.w.n edited the summary of this revision. (Show Details)

Notes:

This Part 1 of the split-up of the past revision: D140840

nikic added a comment.Jan 4 2023, 9:51 AM

High level comment on these test is that many of them test a combination of folds, rather than their primitive parts. E.g. to test D140851 it would be sufficient to just have an assume followed by an and+icmp to check the known bits. Going through the mul fold to test computeKnownBits() behavior is both unnecessarily indirect, and limited: We can only observe the lowest bit through that, so all tests end up doing something like and x, 1 only. Having some end-to-end tests on motivating patterns is fine, but we mainly should be testing things in isolation. (That would probably also cut down on the total number of tests.)

llvm/test/Transforms/InstCombine/icmp-binop.ll
16

All these zext + ret and be replaced by ret i1.

296

What's the point of these these tests that contain only assume calls?

616

What's the point of these tests?

goldstein.w.n updated this revision to Diff 486421.EditedJan 4 2023, 4:08 PM

Make {X|Y}Extra clearer. Remove some unnecesisarily verbose code.

Didn't update, was update 2 and 3.

goldstein.w.n added inline comments.Jan 4 2023, 4:19 PM
llvm/test/Transforms/InstCombine/icmp-binop.ll
16

All these zext + ret and be replaced by ret i1.

Figured no difference. Do you want all unnecessary zext removed?

296

These tests are more for patterns 3/4.

616

What's the point of these tests?

None, I write the tests in C -> ll. Guess this one got optimized. I'll drop in next revision to this patch.

High level comment on these test is that many of them test a combination of folds, rather than their primitive parts. E.g. to test D140851 it would be sufficient to just have an assume followed by an and+icmp to check the known bits. Going through the mul fold to test computeKnownBits() behavior is both unnecessarily indirect, and limited:

Fair enough, when I wrote this initially I was trying to fix a missed optimization in the mul case so wrote my tests based on that.

We can only observe the lowest bit through that, so all tests end up doing something like and x, 1 only. Having some end-to-end tests on motivating patterns is fine, but we mainly should be testing things in isolation. (That would probably also cut down on the total number of tests.)

Is your preference for me to remove some of these tests? My general feeling is more is better than less, even if they become
a bit redundant. When working on the patch (only working with u32) I think at some point or another just about every case
broke at some point so I generally see them as useful.

The s64 case (that was able to optimize before the patch b.c of NSW) is useless so will drop, but the other "trivially"
different cases seem worth keeping.

Regarding new tests for patches 3/4. Would your preference be:

  1. Add them in this review
  2. Add them to the reviews for patches 3/4 respectively
  3. Create 2 new reviews (one for each).

Propegating changes from rebase

Any changes needed for this series?

Rebase + update tests

ping (note these tests are now only for D140850 as the series has been split).

goldstein.w.n retitled this revision from [Patch 1/4]: Add tests for binops with conditions/assume constraints to [InstCombine] Add tests for binops with conditions/assume constraints.Jan 17 2023, 11:35 AM

Remove 4000 lines of tests

nikic added a comment.Jan 27 2023, 1:31 AM

I think we're stilling missing a test where the icmp constant is not zero.

llvm/test/Transforms/InstCombine/icmp-binop.ll
26

Either this should be ne or the test name adjusted.

103

Was this supposed to be a 0 (or an eq)? Otherwise this is assuming even, not odd.

247

I think we're still missing a test where the second op is non-zero, so maybe change %v to %v2 here?

goldstein.w.n marked 5 inline comments as done.Jan 27 2023, 11:18 AM

I think we're stilling missing a test where the icmp constant is not zero.

Added.

nikic accepted this revision.Jan 27 2023, 12:53 PM

LGTM, thanks!

This revision is now accepted and ready to land.Jan 27 2023, 12:53 PM

LGTM, thanks!

Thank you for the help, will write better tests in the future!