Skip to content

Commit 7828030

Browse files
committed
scev/niter: Use INTEGRAL_NB_TYPE_P instead of direct comparison to INTEGER_TYPE [PR124061]
I noticed this while looking into PR 124052. This is not the first time we had direct type comparison against INTEGER_TYPE which should have been different. As mention in PR 124052, I didn't include bool types so I needed a new macro to simplify things. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/124061 gcc/ChangeLog: * tree-scalar-evolution.cc (interpret_rhs_expr): Use INTEGRAL_NB_TYPE_P instead of comparing the code to INTEGER_TYPE. * tree-ssa-loop-niter.cc (number_of_iterations_ne): Likewise. (number_of_iterations_cltz): Likewise. (number_of_iterations_exit_assumptions): Likewise. * tree.h (INTEGRAL_NB_TYPE_P): New macro. gcc/testsuite/ChangeLog: * g++.dg/opt/enum-loop-1.C: New test. * gcc.dg/tree-ssa/bitint-loop-opt-1.c: New test. Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
1 parent 5385c95 commit 7828030

5 files changed

Lines changed: 41 additions & 6 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// PR tree-optimization/124061
2+
// { dg-do compile { target c++11 } }
3+
// { dg-options "-O2 -fdump-tree-sccp" }
4+
5+
enum a : unsigned {};
6+
7+
int f(a limit)
8+
{
9+
a i;
10+
for(i = (a)0; i < limit; i = a(i + 1))
11+
;
12+
return i;
13+
}
14+
15+
// { dg-final { scan-tree-dump "final value replacement:" sccp } }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* PR tree-optimization/124061 */
2+
/* { dg-do compile { target bitint } } */
3+
/* { dg-options "-O2 -fdump-tree-sccp" } */
4+
5+
int f(_BitInt(64) limit)
6+
{
7+
_BitInt(64) i;
8+
for(i = 0; i < limit; i++)
9+
;
10+
return i;
11+
}
12+
13+
/* { dg-final { scan-tree-dump "final value replacement:" sccp } } */

gcc/tree-scalar-evolution.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,8 +1897,8 @@ interpret_rhs_expr (class loop *loop, gimple *at_stmt,
18971897
the operation done in an unsigned type of the same precision
18981898
as the final truncation. We cannot derive a scalar evolution
18991899
for the widened operation but for the truncated result. */
1900-
if (TREE_CODE (type) == INTEGER_TYPE
1901-
&& TREE_CODE (TREE_TYPE (rhs1)) == INTEGER_TYPE
1900+
if (INTEGRAL_NB_TYPE_P (type)
1901+
&& INTEGRAL_NB_TYPE_P (TREE_TYPE (rhs1))
19021902
&& TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (rhs1))
19031903
&& TYPE_OVERFLOW_UNDEFINED (type)
19041904
&& TREE_CODE (rhs1) == SSA_NAME

gcc/tree-ssa-loop-niter.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ number_of_iterations_ne (class loop *loop, tree type, affine_iv *iv,
10541054
if (tree_int_cst_sign_bit (iv->step))
10551055
{
10561056
cond = fold_build2 (GE_EXPR, boolean_type_node, iv->base, final);
1057-
if (TREE_CODE (type) == INTEGER_TYPE)
1057+
if (INTEGRAL_NB_TYPE_P (type))
10581058
{
10591059
/* Only when base - step doesn't overflow. */
10601060
t = TYPE_MAX_VALUE (type);
@@ -1071,7 +1071,7 @@ number_of_iterations_ne (class loop *loop, tree type, affine_iv *iv,
10711071
else
10721072
{
10731073
cond = fold_build2 (LE_EXPR, boolean_type_node, iv->base, final);
1074-
if (TREE_CODE (type) == INTEGER_TYPE)
1074+
if (INTEGRAL_NB_TYPE_P (type))
10751075
{
10761076
/* Only when base - step doesn't underflow. */
10771077
t = TYPE_MIN_VALUE (type);
@@ -2439,7 +2439,7 @@ number_of_iterations_cltz (loop_p loop, edge exit,
24392439
iv_2 = gimple_assign_rhs1 (test_value_stmt);
24402440
tree rhs_type = TREE_TYPE (iv_2);
24412441
if (TREE_CODE (iv_2) != SSA_NAME
2442-
|| TREE_CODE (rhs_type) != INTEGER_TYPE
2442+
|| !INTEGRAL_NB_TYPE_P (rhs_type)
24432443
|| (TYPE_PRECISION (rhs_type)
24442444
!= TYPE_PRECISION (test_value_type)))
24452445
return false;
@@ -3275,7 +3275,7 @@ number_of_iterations_exit_assumptions (class loop *loop, edge exit,
32753275
op1 = gimple_cond_rhs (stmt);
32763276
type = TREE_TYPE (op0);
32773277

3278-
if (TREE_CODE (type) != INTEGER_TYPE
3278+
if (!INTEGRAL_NB_TYPE_P (type)
32793279
&& !POINTER_TYPE_P (type))
32803280
return false;
32813281

gcc/tree.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,13 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int,
617617
|| TREE_CODE (TYPE) == INTEGER_TYPE \
618618
|| TREE_CODE (TYPE) == BITINT_TYPE)
619619

620+
/* Nonzero if TYPE represents an integral type (non-boolean). */
621+
622+
#define INTEGRAL_NB_TYPE_P(TYPE) \
623+
(TREE_CODE (TYPE) == ENUMERAL_TYPE \
624+
|| TREE_CODE (TYPE) == INTEGER_TYPE \
625+
|| TREE_CODE (TYPE) == BITINT_TYPE)
626+
620627
/* Nonzero if TYPE represents an integral type, including complex
621628
and vector integer types. */
622629

0 commit comments

Comments
 (0)