[llvm] 3c7d48e - [NFC][SCEV] Recognize umin_seq when operand is zext'ed in umin but not in zero-check

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 16 11:17:23 PST 2022


This and the next commits are obviously not NFC, i've accidentally
unintentionally marked them as such.

On Wed, Feb 16, 2022 at 10:16 PM Roman Lebedev via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
>
> Author: Roman Lebedev
> Date: 2022-02-16T22:16:02+03:00
> New Revision: 3c7d48ed902a7136a131c1288d75bfcf7af557c6
>
> URL: https://github.com/llvm/llvm-project/commit/3c7d48ed902a7136a131c1288d75bfcf7af557c6
> DIFF: https://github.com/llvm/llvm-project/commit/3c7d48ed902a7136a131c1288d75bfcf7af557c6.diff
>
> LOG: [NFC][SCEV] Recognize umin_seq when operand is zext'ed in umin but not in zero-check
>
> zext(umin(x,y)) == umin(zext(x),zext(y))
> zext(x) == 0  ->  x == 0
>
> Extra leading zeros do not affect the result of comparison with zero,
> nor do they matter for the unsigned min/max,
> so we should not be dissuaded when we find a zero-extensions,
> but instead we should just skip it.
>
> Added:
>
>
> Modified:
>     llvm/lib/Analysis/ScalarEvolution.cpp
>     llvm/test/Analysis/ScalarEvolution/logical-operations.ll
>
> Removed:
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
> index 6170bb8a5db3..2922ca2588e1 100644
> --- a/llvm/lib/Analysis/ScalarEvolution.cpp
> +++ b/llvm/lib/Analysis/ScalarEvolution.cpp
> @@ -5898,8 +5898,9 @@ bool SCEVMinMaxExprContains(const SCEV *Root, const SCEV *OperandToFind,
>
>      bool canRecurseInto(SCEVTypes Kind) const {
>        // We can only recurse into the SCEV expression of the same effective type
> -      // as the type of our root SCEV expression.
> -      return RootKind == Kind || NonSequentialRootKind == Kind;
> +      // as the type of our root SCEV expression, and into zero-extensions.
> +      return RootKind == Kind || NonSequentialRootKind == Kind ||
> +             scZeroExtend == Kind;
>      };
>
>      FindClosure(const SCEV *OperandToFind, SCEVTypes RootKind)
> @@ -6006,13 +6007,14 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
>      // x == 0 ? 0 : umin_seq(..., x, ...)  ->  umin_seq(x, umin_seq(...))
>      // x == 0 ? 0 : umin    (..., umin_seq(..., x, ...), ...)
>      //                    ->  umin_seq(x, umin (..., umin_seq(...), ...))
> -    if (getTypeSizeInBits(LHS->getType()) == getTypeSizeInBits(I->getType()) &&
> +    if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType()) &&
>          isa<ConstantInt>(RHS) && cast<ConstantInt>(RHS)->isZero() &&
>          isa<ConstantInt>(TrueVal) && cast<ConstantInt>(TrueVal)->isZero()) {
>        const SCEV *X = getSCEV(LHS);
>        const SCEV *FalseValExpr = getSCEV(FalseVal);
>        if (SCEVMinMaxExprContains(FalseValExpr, X, scSequentialUMinExpr))
> -        return getUMinExpr(X, FalseValExpr, /*Sequential=*/true);
> +        return getUMinExpr(getNoopOrZeroExtend(X, I->getType()), FalseValExpr,
> +                           /*Sequential=*/true);
>      }
>      break;
>    default:
>
> diff  --git a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
> index 85144defae36..aca7cf37a6f9 100644
> --- a/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
> +++ b/llvm/test/Analysis/ScalarEvolution/logical-operations.ll
> @@ -672,7 +672,7 @@ define i32 @umin_seq_x_y_zext_in_umin(i8 %x.narrow, i32 %y) {
>  ; CHECK-NEXT:    %umin = call i32 @llvm.umin.i32(i32 %y, i32 %x)
>  ; CHECK-NEXT:    --> ((zext i8 %x.narrow to i32) umin %y) U: [0,256) S: [0,256)
>  ; CHECK-NEXT:    %r = select i1 %x.is.zero, i32 0, i32 %umin
> -; CHECK-NEXT:    --> %r U: [0,256) S: [0,256)
> +; CHECK-NEXT:    --> ((zext i8 %x.narrow to i32) umin_seq %y) U: [0,256) S: [0,256)
>  ; CHECK-NEXT:  Determining loop execution counts for: @umin_seq_x_y_zext_in_umin
>  ;
>    %x = zext i8 %x.narrow to i32
> @@ -708,7 +708,7 @@ define i32 @umin_seq_x_y_zext_of_umin(i8 %x, i8 %y) {
>  ; CHECK-NEXT:    %umin = zext i8 %umin.narrow to i32
>  ; CHECK-NEXT:    --> (zext i8 (%x umin %y) to i32) U: [0,256) S: [0,256)
>  ; CHECK-NEXT:    %r = select i1 %x.is.zero, i32 0, i32 %umin
> -; CHECK-NEXT:    --> %r U: [0,256) S: [0,256)
> +; CHECK-NEXT:    --> ((zext i8 %x to i32) umin_seq (zext i8 (%x umin %y) to i32)) U: [0,256) S: [0,256)
>  ; CHECK-NEXT:  Determining loop execution counts for: @umin_seq_x_y_zext_of_umin
>  ;
>    %umin.narrow = call i8 @llvm.umin.i8(i8 %y, i8 %x)
>
>
>
> _______________________________________________
> 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