[PATCH] D51942: [InstCombine] Fold (C/x)>0 into x>0 if possible
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 25 12:30:48 PDT 2018
spatel added a comment.
In https://reviews.llvm.org/D51942#1245429, @marels wrote:
> Thank you for the input,
>
> I updated the code to support vectors using the match API. But before uploading I have question.
>
> I was not able to find a way to match the following predicates with the existing API.
>
> 1. All elements are non-zero
> 2. All elements are positive
> 3. All elements are negative
>
> These are important to correctly handle some cases:
>
> The following cannot be folded because the new predicate is ambiguous. C = <2 x float> <float 1.0, float -1.0>
>
> The following cannot be folded because the one element violates the assumption that C=0. C = <2 x float> <float 1.0, float 0.0>
>
> This is not a big thing because it can be easily added to to PatternMatch.h (same implementation as m_AnyZeroFP). I think it is better submit a separate change for this. Do you agree, or shall I bunch both changes together?
Sorry this wasn't clear - I was only suggesting that we handle vector splat (all constants within the vector are identical or undef) patterns in this patch. You're correct that handling arbitrary vector constants is a harder problem. The API I would use here is "m_APFloat" (it deals with splat constants internally, so you probably don't need to do anything special in the calling code for this patch).
> @spatel what do you think about @john.brawn suggestion to removing the hasAllowReciprocal check?
That sounds correct - I don't think you don't need it here.
But that does raise the question: are you planning to generalize this transform? I see a few possible enhancements:
1. Handle (X / C) < 0.0 (constant is divisor rather than dividend
2. Handle (X * C) < 0.0 (multiplication rather than division)
3. Handle all of the above with non-zero compare constant: (X / C1) < C2, (C1 / X) < C2, (X * C1) < C2
Repository:
rL LLVM
https://reviews.llvm.org/D51942
More information about the llvm-commits
mailing list