abs(x-y) --> x-y where x >= y, done on D122013
abs(x-y) --> y-x where x <= y
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Can you add alive2 links?
llvm/test/Transforms/InstCombine/abs-intrinsic.ll | ||
---|---|---|
533 | Can you split the new tests to a separate commit? |
Thanks for your attention, I already put the each alive2 link before the matched cases, so do you mean I also should put that in the MR description ?
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1032 | This looks incorrect from the perspective of the getKnownSign() API. You are returning sign 1 for value 0, which is incorrect. It does work out for the abs optimization because -0 == 0, but it may matter in other cases. |
address comment, move the transform out of the getKnownSign to avoid breaking the perspective of the getKnownSign() API
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1032 | thanks, I move it out of the getKnownSign() API. | |
llvm/test/Transforms/InstCombine/abs-intrinsic.ll | ||
533 | Done on https://reviews.llvm.org/D156521, thanks |
Bah sorry for not following up on this, but where are the alive2 links?
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1540 | This is incorrect if the abs allows INT_MIN: https://alive2.llvm.org/ce/z/YNcdRW |
Thanks for your attention, I already put the each alive2 link before the matched cases, so do you mean I also should put that in the MR description ?
Bah sorry for not following up on this, but where are the alive2 links?
hi @goldstein.w.n,I usually add the alive2 links before the matched cases because there is more than 1 case, such as line 455 in file Transforms/InstCombine/abs-intrinsic.ll (it is more obvious on D156521)
do you mean it is better to put that in the MR description, too ?
MR?
I mean the commit message of this patch (and summary in phab if the two should ever desync).
Address comment
1、Add proof link alive2, https://alive2.llvm.org/ce/z/KkeEsd
2、abs allows INT_MIN,and its related tests
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1521 | You also do abs(x-y) --> x - y where x > y. |
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1521 | Apply your comment, thanks |
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1537 | Sorry, noticed this a bit late, but is there a way we can avoid essentially recreating the logic below and instead just add something like getKnownSignOrZero which wraps getKnownSign but also tries SLE if the SLT analysis isn't fruitful? Then you could just replace the function here and we wouldn't need to duplicate so much codes. |
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | ||
---|---|---|
1537 | Thanks for your idea. I try that, it work, but will missing nsw for some case, such as src_sub_abs_sleF.
|
LGTM.
llvm/test/Transforms/InstCombine/abs-intrinsic.ll | ||
---|---|---|
578 | Imo missing a test with sge i8 %y, %x. Also missing a test where the sub is in the false case (i.e sgt %x, %y but abs in false case). |
llvm/test/Transforms/InstCombine/abs-intrinsic.ll | ||
---|---|---|
578 | Done, thanks! Added new cases sub_abs_sgeT_swap and sub_abs_sgeT_false |
This looks incorrect from the perspective of the getKnownSign() API. You are returning sign 1 for value 0, which is incorrect. It does work out for the abs optimization because -0 == 0, but it may matter in other cases.