Page MenuHomePhabricator

Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline

XChy (Hongyu Chen)
User

Projects

User does not belong to any projects.

User Details

User Since
Jun 27 2023, 10:34 PM (22 w, 4 d)

Recent Activity

Sep 24 2023

XChy closed D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
Sep 24 2023, 7:18 PM · Restricted Project, Restricted Project
XChy accepted D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
Sep 24 2023, 7:18 PM · Restricted Project, Restricted Project
XChy closed D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Sep 24 2023, 7:17 PM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Thanks for @DianQK and @nikic! This patch will be submitted as Github PR (It seems that doc
about submitting by Phabricator has been removed).

Sep 24 2023, 6:31 PM · Restricted Project, Restricted Project

Sep 21 2023

XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Polish comments.

Sep 21 2023, 2:31 AM · Restricted Project, Restricted Project

Sep 20 2023

XChy added inline comments to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Sep 20 2023, 12:39 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Keep order when updating dom-tree.

Sep 20 2023, 12:37 AM · Restricted Project, Restricted Project

Sep 19 2023

XChy added inline comments to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Sep 19 2023, 11:55 PM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Polish comment and fix when to print log.

Sep 19 2023, 8:35 PM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Reduce irrelevant formatting

Sep 19 2023, 4:21 AM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

LGTM. But before landing, you'd better request @nikic approval for this.

If possible, however, it would be better if there is any other available option that does not modify the original IR.

I don't know. The purpose of your transformation is to tweak this test case.

Sep 19 2023, 4:15 AM · Restricted Project, Restricted Project

Sep 8 2023

XChy added a comment to D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

ping.

nikic is on vacation for the next week, since he requested changes plan to let him get to it when he comes back.
Might have time to review later in the week, however.

Sep 8 2023, 12:05 AM · Restricted Project, Restricted Project

Sep 6 2023

XChy added a comment to D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

ping.

Sep 6 2023, 6:20 AM · Restricted Project, Restricted Project

Sep 4 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Insert use function into jump-table-islands.ll to avoid unrelated transform.

Sep 4 2023, 12:26 AM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

I read the history of jump-table-islands.ll.
This test checks for oversized jump tables jumping over each other.
You transform changes from

end:                                              ; preds = %complex, %simple
  %val = phi i8500 [ %l, %complex ], [ -1, %simple ]
  br label %common.ret

to

end:                                              ; preds = %complex
  br label %common.ret

The test was to check disappears.
Increasing BigInt makes no sense.
Sorry I don't know how to create a friendly diff display.
You could remove -arm-atomic-cfg-tidy=0 and change the end bb to:

end:
  %val = phi %BigInt [ %l, %complex ], [ -1, %simple ]
  %val2 = add %BigInt %val, 1
  ret %BigInt %val2
}

https://reviews.llvm.org/differential/diff/555646/

I feel the SKIP_TABLE name is confusing and should be changed to CONTINUE_TABLE/ISLAND_JUMP?

Sep 4 2023, 12:22 AM · Restricted Project, Restricted Project

Sep 1 2023

XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Simplify LazyGetIndex function, and ready to be reviewed.

Sep 1 2023, 10:32 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Sep 1 2023, 10:21 AM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Too much irrelevant formatting. It causes review to become complicated. It also affects other people blame related changes.
Could you ignore this formatting?

In fact, I'm not sure why. It could be that some commits are not formatted, or it could be a change in formatting rules. Or something else.
My formatting workflow is:

  • Ignore all irrelevant formatting if present.
  • Add and commit.
  • git clang-format HEAD~1
  • Since the latest submission is my own. Then I just run git add . and git clang-format HEAD~1.
Sep 1 2023, 9:48 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Drop unnecessary formatting.

Sep 1 2023, 9:11 AM · Restricted Project, Restricted Project

Aug 31 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Remove unnecessary helper function

Aug 31 2023, 10:42 PM · Restricted Project, Restricted Project

Aug 28 2023

XChy accepted D155711: [SimplifyCFG] Hoist common instructions on Switch..

LGTM. May commit it if no changes are requested by others in one day.

Aug 28 2023, 10:39 PM · Restricted Project, Restricted Project

Aug 12 2023

XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

ping.

Aug 12 2023, 11:59 PM · Restricted Project, Restricted Project
XChy retitled D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB from [SimplifyCFG] Transform for merging the combination of phis in switch to [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Aug 12 2023, 11:59 PM · Restricted Project, Restricted Project

Aug 7 2023

XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Eliminate boundary-check.

Aug 7 2023, 5:12 AM · Restricted Project, Restricted Project

Aug 4 2023

XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Update tests and FIXME: Boundary-check

Aug 4 2023, 7:00 PM · Restricted Project, Restricted Project

Aug 2 2023

XChy added a comment to D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Already limit it to one variable. But I don't know why it is unlikely to be useful. From my perspective For multi-dimensional arrays, it's possible to have more than one index variable.

Besides, there exists miscompilation, I found just now. Current state-machine doesn't emit the CmpInst/Poison to guarrantee the index/offset is always not negative. Lack of such range-check would lead to something triggering UB not to doing so. I need to check it later.

Aug 2 2023, 11:46 AM · Restricted Project, Restricted Project

Aug 1 2023

XChy updated the diff for D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) .
Aug 1 2023, 10:12 AM · Restricted Project, Restricted Project
XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Already limit it to one variable. But I don't know why it is unlikely to be useful. From my perspective For multi-dimensional arrays, it's possible to have more than one index variable.

Aug 1 2023, 10:11 AM · Restricted Project, Restricted Project
XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Complete basically correct fold.

Aug 1 2023, 7:01 AM · Restricted Project, Restricted Project

Jul 31 2023

XChy added a comment to D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

It would be better to base this on collectOffset() and work in offset representation. Especially if you're interested in handling Rust, the type of the global and the GEP / loads will typically not line up (constant globals in Rust are usually i8 arrays, regardless of "real" type.)

Jul 31 2023, 9:46 AM · Restricted Project, Restricted Project
XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Update tests.

Jul 31 2023, 7:59 AM · Restricted Project, Restricted Project
XChy updated the diff for D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) .
Jul 31 2023, 7:58 AM · Restricted Project, Restricted Project
XChy updated the diff for D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) .

Update tests

Jul 31 2023, 7:49 AM · Restricted Project, Restricted Project
XChy updated the summary of D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.
Jul 31 2023, 7:19 AM · Restricted Project, Restricted Project
XChy updated the diff for D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

Extends foldCmpLoadFromIndexedGlobal to fold.

Jul 31 2023, 7:02 AM · Restricted Project, Restricted Project
XChy updated the diff for D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) .

Extend foldCmpLoadFromIndexedGlobal and use load-cmp.ll as test file.

Jul 31 2023, 6:58 AM · Restricted Project, Restricted Project
XChy retitled D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) from [ValueTracking][NFC] Tests for folding icmp(constants[x]) to [InstCombine][NFC] Tests for folding icmp(constants[x]) .
Jul 31 2023, 6:55 AM · Restricted Project, Restricted Project
XChy added a comment to D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.

This should be handled by the foldCmpLoadFromIndexedGlobal() fold, by first converting the icmp(load(gep(g, idx))) into icmp(idx) and then folding that icmp against the dominating condition.

That fold currently requires a very specific GEP source element type, but should be easy to generalize.

Jul 31 2023, 3:09 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Update AArch64's codegen tests.

Jul 31 2023, 3:06 AM · Restricted Project, Restricted Project
XChy retitled D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given from [ValueTracking][NFC] Fold icmp(constants[x]) when the range of x is given to [ValueTracking][InstCombine] Fold icmp(constants[x]) when the range of x is given.
Jul 31 2023, 2:30 AM · Restricted Project, Restricted Project
XChy requested review of D156657: [InstCombine] Fold icmp(constants[x]) when the range of x is given.
Jul 31 2023, 2:25 AM · Restricted Project, Restricted Project
XChy added reviewers for D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) : nikic, goldstein.w.n.
Jul 31 2023, 2:15 AM · Restricted Project, Restricted Project
XChy requested review of D156656: [InstCombine][NFC] Tests for folding icmp(constants[x]) .
Jul 31 2023, 2:15 AM · Restricted Project, Restricted Project

Jul 30 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

[Clang-format]
It seems perform correctly and well in most cases.

Jul 30 2023, 3:53 AM · Restricted Project, Restricted Project

Jul 29 2023

XChy added a comment to D155711: [SimplifyCFG] Hoist common instructions on Switch..

Nice work to me! Just some nits here.
Can you create two patches to better show the difference before/after transform?
The first patch includes your unoptimized testcases without the fold. (Your first commit)
The second patch includes your optimized testcases and your code for the fold. (Your second commit, which is based on your first commit)
And then let the first patch be the parent revision of the second patch through "Edit Related Revisions".

Jul 29 2023, 11:02 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Update codesize-loop.ll

Jul 29 2023, 6:20 AM · Restricted Project, Restricted Project
XChy updated the diff for D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.

Add test for generalization.

Jul 29 2023, 2:07 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
  • Add complete positive tests
  • Fix bugs about preserving domtree
Jul 29 2023, 2:05 AM · Restricted Project, Restricted Project

Jul 28 2023

XChy added inline comments to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Jul 28 2023, 9:26 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
  • Refactor TryToSimplifyUncondBranchFromEmptyBlock to merge phis between BB and Succ with a common predecessor. Logic correctly embedded (OK in Local tests), but not efficient currently.
  • A regression found, in switch-simplify-crash2.ll. But InstCombine would solve it.
  • Testcases not added now, incoming. And ARM/jump-islands-table.ll doesn't test well still.
Jul 28 2023, 9:26 AM · Restricted Project, Restricted Project

Jul 27 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Add -arm-atomic-cfg-tidy=0 option.

Jul 27 2023, 8:30 AM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Do you have any particular issues this could cause in mind?

Sure, something like FoldTwoEntryPHINode/HoistThenElseToIf may miss/delay. Or some Phi to Select may be delayed/sunk. I haven't constructed counter-examples here. (Maybe it's my intuitive fault, I actually constructed some examples optimized well).
I think the probitability can be tested by the existing testcases here. I'll try to generalize TryToSimplifyUncondBranchFromEmptyBlock to perform the tests.

I think even if we don't always perform the transform, we should still express it generically, and then have a profitability heuristic on top: E.g. say that the one common predecessor must have a switch terminator. That way we can clearly separate correctness from profitability requirements.

I agree with you. The generalization is indeed necessary. It may take some time to complete it. At that time can we determine what profitability heuristic shoud be.

Edit: Just for reference, this is an example of the non-switch CFG I have in mind where such a transform should be possible: https://gist.github.com/nikic/8f22ef4e366fd3041c7e150c228f9673

Thanks! That could serve as a testcase to be expanded/reduced.

Jul 27 2023, 8:00 AM · Restricted Project, Restricted Project
XChy updated the diff for D156395: [Reassociate][NFC] Update the header comment of Reassociate Pass.

Emphasize ordering.

Jul 27 2023, 6:48 AM · Restricted Project, Restricted Project

Jul 26 2023

XChy requested review of D156395: [Reassociate][NFC] Update the header comment of Reassociate Pass.
Jul 26 2023, 10:48 PM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Omit jump-table-islands.ll test temporarily. (Sorry, I'm not familiar with ARM and unable to update it)
Contact related committers to update if this patch is approved.

Jul 26 2023, 1:28 AM · Restricted Project, Restricted Project

Jul 25 2023

XChy added inline comments to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Jul 25 2023, 7:32 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
  • Fix the nits
  • Change the order of checks to increase efficiency.
Jul 25 2023, 7:30 AM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Here is an optimized example related to the lookup table optimization in the issue in summary:
add 1

Jul 25 2023, 12:14 AM · Restricted Project, Restricted Project

Jul 24 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
  • Fix the nits
  • Clear the logic
Jul 24 2023, 10:38 AM · Restricted Project, Restricted Project
XChy added a comment to D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Thanks for your review! I understand your framing and it clear my mind. This framing is much general, not just for switch. And as you analyse, actually, a large part of the logic of this patch is copied from TryToSimplifyUncondBranchFromEmptyBlock, specified for switch. I restrict this fold in a narrow situation. Though this transformation is not directly related to switch, but I didn't apply such mergence to all BasicBlocks, since it's not always worthwhile as you say.

Jul 24 2023, 10:35 AM · Restricted Project, Restricted Project
XChy added a comment to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

LGTM

Jul 24 2023, 3:32 AM · Restricted Project, Restricted Project
XChy added inline comments to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 24 2023, 3:28 AM · Restricted Project, Restricted Project
XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
  • Add m_OneUse guard to zext(icmp).
Jul 24 2023, 3:27 AM · Restricted Project, Restricted Project

Jul 23 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
  • Fix all the nits.
  • Extract the logic of canMergePhisOfCase
Jul 23 2023, 11:28 PM · Restricted Project, Restricted Project
XChy added a comment to D156026: [InstCombine] Contracting x^2 + 2*x*y + y^2 to (x + y)^2 (integer).

Maybe you need to create two patch.
The first patch includes your unoptimized testcases without the fold. (Your first commit)
The second patch includes optimized testcases and the code for the fold. (Your second commit, which is based on your first commit)
And then you should let the first patch be the parent revision of the second patch through "Edit Related Revisions".

Jul 23 2023, 8:52 PM · Restricted Project, Restricted Project
XChy added inline comments to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 23 2023, 8:45 PM · Restricted Project, Restricted Project
XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
  • Apply m_OneUse guard to lshr.
  • Fix nits
Jul 23 2023, 8:34 PM · Restricted Project, Restricted Project
XChy added a comment to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

ping.

Jul 23 2023, 9:59 AM · Restricted Project, Restricted Project

Jul 22 2023

XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Fix the bugs of merging the phis from the BasicBlock out of switch.

Jul 22 2023, 7:39 PM · Restricted Project, Restricted Project

Jul 21 2023

XChy added inline comments to D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
Jul 21 2023, 9:52 PM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
  • Preserve domtree
Jul 21 2023, 7:39 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.

Avoid infinite loops

Jul 21 2023, 7:24 AM · Restricted Project, Restricted Project
XChy updated the diff for D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
Jul 21 2023, 7:23 AM · Restricted Project, Restricted Project
XChy updated the diff for D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
  • Avoid infinite loops
Jul 21 2023, 7:22 AM · Restricted Project, Restricted Project
XChy added a reviewer for D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch: DianQK.
Jul 21 2023, 5:56 AM · Restricted Project, Restricted Project
XChy added a reviewer for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB: DianQK.
Jul 21 2023, 5:54 AM · Restricted Project, Restricted Project
XChy updated the diff for D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Jul 21 2023, 4:19 AM · Restricted Project, Restricted Project
XChy updated the diff for D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
Jul 21 2023, 4:18 AM · Restricted Project, Restricted Project
XChy requested review of D155940: [SimplifyCFG] Transform for redirecting phis between unmergeable BB and SuccBB.
Jul 21 2023, 4:10 AM · Restricted Project, Restricted Project
XChy requested review of D155939: [SimplifyCFG][NFC] Add tests for merging the combination of phis in switch.
Jul 21 2023, 3:49 AM · Restricted Project, Restricted Project

Jul 20 2023

XChy added inline comments to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 20 2023, 9:15 PM · Restricted Project, Restricted Project

Jul 18 2023

XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

Produce zext(bitwise(icmp.icmp))

Jul 18 2023, 7:14 PM · Restricted Project, Restricted Project

Jul 16 2023

XChy added inline comments to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 16 2023, 8:26 PM · Restricted Project, Restricted Project
XChy added a comment to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

ping.

Jul 16 2023, 9:43 AM · Restricted Project, Restricted Project
XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

Limit the fold for multiuse cases

Jul 16 2023, 6:32 AM · Restricted Project, Restricted Project

Jul 14 2023

XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

Add xor tests

Jul 14 2023, 7:19 AM · Restricted Project, Restricted Project
XChy updated the diff for D154789: [InstCombine] Add tests for bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC).
Jul 14 2023, 7:17 AM · Restricted Project, Restricted Project

Jul 13 2023

XChy added a comment to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

I update the diff to ensure that we fold exactly what can be folded by foldXorOfICmps and foldAndOrOfICmps.

However, I'm not sure what unexpected result the code below may bring.

// remove the deferred 2 instructions : 
// icmp slt A, 0
// bitwise (A < 0, icmp) 
// otherwise there will be infinite loops of combining
Worklist.popDeferred()->eraseFromParent();
Worklist.popDeferred()->eraseFromParent();
Jul 13 2023, 6:42 AM · Restricted Project, Restricted Project
XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

I update the diff to ensure that we fold exactly what can be folded by foldXorOfICmps and foldAndOrOfICmps.

Jul 13 2023, 5:28 AM · Restricted Project, Restricted Project

Jul 12 2023

XChy added inline comments to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 12 2023, 8:45 AM · Restricted Project, Restricted Project
XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

[clang-format]

Jul 12 2023, 4:19 AM · Restricted Project, Restricted Project

Jul 11 2023

XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 11 2023, 11:27 PM · Restricted Project, Restricted Project
XChy updated the diff for D154789: [InstCombine] Add tests for bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC).
Jul 11 2023, 11:25 PM · Restricted Project, Restricted Project
XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 11 2023, 4:48 AM · Restricted Project, Restricted Project
XChy updated the diff for D154789: [InstCombine] Add tests for bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC).
Jul 11 2023, 4:44 AM · Restricted Project, Restricted Project

Jul 10 2023

XChy updated the diff for D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..
Jul 10 2023, 6:44 AM · Restricted Project, Restricted Project
XChy updated the diff for D154789: [InstCombine] Add tests for bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC).
Jul 10 2023, 6:41 AM · Restricted Project, Restricted Project

Jul 9 2023

XChy added a comment to D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold..

The basic idea here is reasonable, but you need to be very careful about infinite loops: If you replace the shift with zext+icmp and it does *not* get folded afterwards, it will be converted back to the shift, and so on. I don't think the fold is guaranteed to happen, e.g. due to some unlucky interaction with shouldOptimizeCast().

I would recommend to instead directly produce the zext(binop(icmp, icmp)) sequence, rather than letting the following fold handle it.

Please add:

  • Multi-use test.
  • Test where we do not get any beneficial fold out of converting the lshr back into an icmp.

Depending on how the latter case looks like, we might want to further limit this -- e.g. does it make sense to do this if the lshr and icmp work on different variables or not?

Jul 9 2023, 11:18 PM · Restricted Project, Restricted Project
XChy updated the summary of D154126: [InstCombine] Transform (A > 0) | (A < 0) -> zext (A != 0) fold.
Jul 9 2023, 5:29 PM · Restricted Project, Restricted Project
XChy retitled D154789: [InstCombine] Add tests for bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC) from [InstCombine] Add tests for bitwise (A << C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC) to [InstCombine] Add tests for bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A<0, icmp)) fold (NFC).
Jul 9 2023, 5:28 PM · Restricted Project, Restricted Project