Tried implementing SPF_ABS and instcombine for ABS(ABS(X))
I left ABS(-X) -> ABS(X) from TODO comment because it was not
reducing instructions count. For calculating ABS(X), it generate
instruction to negate X for select instruction.
Paths
| Differential D3658
Added instcombine for 'ABS(ABS(X)) -> ABS(X)' ClosedPublic Authored by dinesh.d on May 7 2014, 12:53 PM.
Details Summary Tried implementing SPF_ABS and instcombine for ABS(ABS(X)) I left ABS(-X) -> ABS(X) from TODO comment because it was not
Diff Detail Event Timelinedinesh.d updated this object.
Comment Actions updated code to handle following patterns [Thanks for pointing out] // (X > 0) ? X : -X // (X < 0) ? -X : X // (X > 1) ? -X : X Comment Actions corrected one typo in comments. (x > 1)? -x : x whereas I meant (x < 1)? -x : x Comment Actions One potential bug, and a couple of small comments, but otherwise looks fine. (Note: I don't have commit rights so this is not an approval to commit.)
Comment Actions Thanks Philip. I appreciate your effort. I do have one request though. As you are also new to llvm, it will be great if you can avoid
Comment Actions Updated patch to handle both ABS(X) and NEG(ABS(X)) and tests for all possible combinations or ABS(ABS) and NABS(NABS) Comment Actions With the last round of changes, this looks fine to me. I'm unclear whether this is covering all useful patterns (i.e. why don't we need GTE, or LTE pattens?), but what's here seems correct and useful. Reminder: You will need to find another reviewer. I do not have commit rights and can not approve your change. Comment Actions Thanks for review, Philip. InstCombine code changes >= and <= to corrosponding > and < before this code get hit. > cat test.cpp int test(int x) { int y = (x >= 0) ? x : -x; int z = (y >= 0) ? y : -y; return z; } > clang -O0 -S -emit-llvm test.cpp > opt -mem2reg -instcombine -debug test.ll Let me know if you have any doubts. bkramer edited edge metadata. Comment ActionsThe updated patch LGTM. Thanks! We don't have to match patterns for sle and uge as instcombine canonicalizes them into slt and ugt. That makes code like this simpler. This revision is now accepted and ready to land.Jun 5 2014, 11:43 AM
Revision Contents
Diff 9955 lib/Transforms/InstCombine/InstCombine.h
lib/Transforms/InstCombine/InstCombineSelect.cpp
test/Transforms/InstCombine/abs_abs.ll
|
Personally, I find the code with these extracted much harder to read. I would prefer you not extract these, but don't have a strong preference. i.e. feel free to ignore