[SCEV] Compute AddRec range computations using different type BECount

Before this patch, we can only use the MaxBECount for an AddRec's range
computation if the MaxBECount has <= bit width of the AddRec. This patch
reasons that if a MaxBECount has > bit width, and is <= the max value of
AddRec's bit width, we can still use the MaxBECount.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D151698

GitOrigin-RevId: 6ed152aff4aab6307ecaab64a544d0524ea5f50e
diff --git a/test/CodeGen/switch-in-non-affine-region.ll b/test/CodeGen/switch-in-non-affine-region.ll
index 8eeabd9..930755e 100644
--- a/test/CodeGen/switch-in-non-affine-region.ll
+++ b/test/CodeGen/switch-in-non-affine-region.ll
@@ -14,13 +14,13 @@
 ;          }
 ;    }
 ;
-; CHECK: polly.stmt.if.then:
-; CHECK:   %[[trunc:.*]] = trunc i64 %polly.indvar to i32
-; CHECK:   %p_rem = srem i32 %[[trunc]], 4
-; CHECK:   switch i32 %p_rem, label %polly.stmt.sw.epilog [
-; CHECK:     i32 0, label %polly.stmt.sw.bb
-; CHECK:     i32 1, label %polly.stmt.sw.bb.3
-; CHECK:   ]
+; CHECK:      polly.stmt.if.then:
+; CHECK-NEXT:   %2 = trunc i64 %polly.indvar to i2
+; CHECK-NEXT:   %3 = zext i2 %2 to i32
+; CHECK-NEXT:   switch i32 %3, label %polly.stmt.sw.epilog [
+; CHECK-NEXT:     i32 0, label %polly.stmt.sw.bb
+; CHECK-NEXT:     i32 1, label %polly.stmt.sw.bb.3
+; CHECK-NEXT:   ]
 ;
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 
diff --git a/test/ScopInfo/NonAffine/non-affine-loop-condition-dependent-access_3.ll b/test/ScopInfo/NonAffine/non-affine-loop-condition-dependent-access_3.ll
index b11675b..463db23 100644
--- a/test/ScopInfo/NonAffine/non-affine-loop-condition-dependent-access_3.ll
+++ b/test/ScopInfo/NonAffine/non-affine-loop-condition-dependent-access_3.ll
@@ -14,7 +14,7 @@
 ; INNERMOST-NEXT: Invariant Accesses: {
 ; INNERMOST-NEXT: }
 ; INNERMOST-NEXT: Context:
-; INNERMOST-NEXT: [p_0, p_1, p_2] -> {  : 0 <= p_0 <= 2147483647 and 0 <= p_1 <= 1024 and 0 <= p_2 <= 1024 }
+; INNERMOST-NEXT: [p_0, p_1, p_2] -> {  : 0 <= p_0 <= 1048576 and 0 <= p_1 <= 1024 and 0 <= p_2 <= 1024 }
 ; INNERMOST-NEXT: Assumed Context:
 ; INNERMOST-NEXT: [p_0, p_1, p_2] -> {  :  }
 ; INNERMOST-NEXT: Invalid Context:
@@ -89,9 +89,9 @@
 ; ALL-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
 ; ALL-NEXT:             { Stmt_bb15__TO__bb25[i0, i1] -> MemRef_A[i1] };
 ; ALL-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
-; ALL-NEXT:             { Stmt_bb15__TO__bb25[i0, i1] -> MemRef_A[o0] : 0 <= o0 <= 2147483647 };
+; ALL-NEXT:             { Stmt_bb15__TO__bb25[i0, i1] -> MemRef_A[o0] : 0 <= o0 <= 1048576 };
 ; ALL-NEXT:         MayWriteAccess :=    [Reduction Type: NONE] [Scalar: 0]
-; ALL-NEXT:             { Stmt_bb15__TO__bb25[i0, i1] -> MemRef_A[o0] : 0 <= o0 <= 2147483647 };
+; ALL-NEXT:             { Stmt_bb15__TO__bb25[i0, i1] -> MemRef_A[o0] : 0 <= o0 <= 1048576 };
 ; ALL-NEXT: }
 ;
 ;    void f(int *A) {