[PATCH] D17859: [InstCombine] convert 'isPositive' and 'isNegative' vector comparisons to shifts (PR26701, PR26819)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 24 17:21:53 PDT 2016
spatel added inline comments.
Comment at: lib/Transforms/InstCombine/InstCombineCasts.cpp:985
@@ +984,3 @@
+ // because vector ISAs may not have a full range of comparison
+ // operators. This cmp+sext transform, however, will simplify the IR, so
+ // we always do it.
> I usually see canonicalization as something that is target independent, and then after optimization the lowering can adjust toward something that the target will "like" (ultimately the SDAG legalizer is doing this). Any comment?
That sounds right to me in general. But are you suggesting that we should do the comparison canonicalizations for vector types too? Ie, (x <=s -1) --> (x <s 0).
My code comment here is my assumption about why we *don't* do that - vector ISAs may have limited functionality, so some backends (x86 at least) would have to then undo that canonicalization.
I see 2 reasons to justify this patch as written:
1. The shift transform is an actual IR optimization, not just a canonicalization - it reduces the instruction count and/or complexity of the IR.
2. We're already doing this (shift) transform for some comparisons, so we might as well include the other, related comparison operators where it can apply.
More information about the llvm-commits