[llvm] 7ef2c68 - [InstSimplify] improve efficiency for detecting non-zero value

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 14 15:04:51 PDT 2021


Hm, this seems interesting.

I had been thinking about inverting this API by having the shared code 
return the two pointers which imply equality/inequality and having 
instcombine rewrite the condition.  However, I couldn't find a case 
where the existing logic didn't already do that inversion through some 
other (more general) path.  Do you happen to have an IR fragment where 
we trip this example?  I'd like to take a look at it with that lens.

Philip

On 4/14/21 6:12 AM, Sanjay Patel via llvm-commits wrote:
> Author: Sanjay Patel
> Date: 2021-04-14T09:04:15-04:00
> New Revision: 7ef2c68a3d24af0b0d540e748e8b564180f4e18a
>
> URL: https://github.com/llvm/llvm-project/commit/7ef2c68a3d24af0b0d540e748e8b564180f4e18a
> DIFF: https://github.com/llvm/llvm-project/commit/7ef2c68a3d24af0b0d540e748e8b564180f4e18a.diff
>
> LOG: [InstSimplify] improve efficiency for detecting non-zero value
>
> Stepping through callstacks in the example from D99759 reveals
> this potential compile-time improvement.
>
> The savings come from avoiding ValueTracking's computing known
> bits if we have already dealt with special-case patterns.
>
> Further improvements in this direction seem possible.
>
> This makes a degenerate test based on PR49785 about 40x faster
> (25 sec -> 0.6 sec), but it does not address the larger question
> of how to limit computeKnownBitsFromAssume(). Ie, the original
> test there is still infinite-time for all practical purposes.
>
> Differential Revision: https://reviews.llvm.org/D100408
>
> Added:
>      
>
> Modified:
>      llvm/lib/Analysis/InstructionSimplify.cpp
>
> Removed:
>      
>
>
> ################################################################################
> diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
> index b233a0f3eb2d..08f504a0ce37 100644
> --- a/llvm/lib/Analysis/InstructionSimplify.cpp
> +++ b/llvm/lib/Analysis/InstructionSimplify.cpp
> @@ -3432,6 +3432,8 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
>     if (Value *V = simplifyICmpOfBools(Pred, LHS, RHS, Q))
>       return V;
>   
> +  // TODO: Sink/common this with other potentially expensive calls that use
> +  //       ValueTracking? See comment below for isKnownNonEqual().
>     if (Value *V = simplifyICmpWithZero(Pred, LHS, RHS, Q))
>       return V;
>   
> @@ -3637,7 +3639,9 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
>     }
>   
>     // icmp eq|ne X, Y -> false|true if X != Y
> -  if (ICmpInst::isEquality(Pred) &&
> +  // This is potentially expensive, and we have already computedKnownBits for
> +  // compares with 0 above here, so only try this for a non-zero compare.
> +  if (ICmpInst::isEquality(Pred) && !match(RHS, m_Zero()) &&
>         isKnownNonEqual(LHS, RHS, Q.DL, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) {
>       return Pred == ICmpInst::ICMP_NE ? getTrue(ITy) : getFalse(ITy);
>     }
>
>
>          
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list