This is an archive of the discontinued LLVM Phabricator instance.

[BPF] Undo transformation for LICM.cpp:hoistMinMax()
ClosedPublic

Authored by eddyz87 on Apr 10 2023, 8:37 PM.

Details

Summary

Extended BPFCheckAndAdjustIR pass with sinkMinMax() transformation
that undoes LICM hoistMinMax pass.

The undo transformation converts the following patterns:

x < min(a, b) -> x < a && x < b
x > min(a, b) -> x > a || x > b
x < max(a, b) -> x < a || x < b
x > max(a, b) -> x > a && x > b

Where 'a' or 'b' is a constant.
Also supports sext min(...) ... and zext min(...) ....

Diff Detail

Event Timeline

eddyz87 created this revision.Apr 10 2023, 8:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 8:37 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
eddyz87 updated this revision to Diff 512418.Apr 11 2023, 6:14 AM

Update for test case to workaround windows issue

eddyz87 updated this revision to Diff 512451.Apr 11 2023, 7:36 AM

Order of function parameter evaluation is not defined,
this causes issues for test cases (as indicated by windows
test runs).

eddyz87 updated this revision to Diff 512928.Apr 12 2023, 11:50 AM
  • removed requirement for one of the min() to be a constant
  • added comment on why the transformation is necessary
eddyz87 updated this revision to Diff 513021.Apr 12 2023, 5:08 PM

Update to only operate on loop bodies

The motivation, transformation and tests make sense all look good to me.

eddyz87 updated this revision to Diff 536282.Jun 30 2023, 9:10 AM

Rebase, added a few comments.

eddyz87 published this revision for review.Jun 30 2023, 1:17 PM
eddyz87 added a reviewer: yonghong-song.

Hi Yonghong,

Could you please take a look?
I checked this revision against kernel master and see code generation change in a single test: get_branch_snapshot.c, the test contains pattern in question. No veristat changes for Cilium programs [2].
I also verified that selftests at revision [1] (the last revision before your fixes for check_cond_jmp_op()) are passing when using this revision (and loop6 fails if main is used instead of this revision).
Unfortunately, after thinking on loop6 behavior a bit more I can't suggest a better solution than this.

[1] 360cd42c4e95 ("io_uring: optimise io_req_local_work_add")
[2] https://github.com/anakryiko/cilium

Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 1:17 PM

Hi Yonghong,

Could you please take a look?
I checked this revision against kernel master and see code generation change in a single test: get_branch_snapshot.c, the test contains pattern in question. No veristat changes for Cilium programs [2].
I also verified that selftests at revision [1] (the last revision before your fixes for check_cond_jmp_op()) are passing when using this revision (and loop6 fails if main is used instead of this revision).
Unfortunately, after thinking on loop6 behavior a bit more I can't suggest a better solution than this.

[1] 360cd42c4e95 ("io_uring: optimise io_req_local_work_add")

I think this link [1] is not correct. You probably mean something else.

But, the patch looks good to me. Thanks!

[2] https://github.com/anakryiko/cilium

yonghong-song accepted this revision.Jul 2 2023, 5:00 PM
This revision is now accepted and ready to land.Jul 2 2023, 5:00 PM
This revision was automatically updated to reflect the committed changes.
eddyz87 reopened this revision.Jul 6 2023, 6:25 PM
This revision is now accepted and ready to land.Jul 6 2023, 6:25 PM
eddyz87 updated this revision to Diff 537956.Jul 6 2023, 7:52 PM

Fix for memory leak issue reported by testbot:
https://lab.llvm.org/buildbot/#/builders/5/builds/34931

sounds good to me. could you summarize what caused the memory leak and what is the fix?

sounds good to me. could you summarize what caused the memory leak and what is the fix?

For some reason I used the following sequence to remove unused instructions (e.g. min/max intrinsic calls):

I->dropAllReferences();
I->removeFromParent();

While correct way to do it is:

I->eraseFromParent();

I have this noted alongside sha's of first commit and revert in the git commit message locally.

I see. thanks for explanation!

This revision was automatically updated to reflect the committed changes.