From 8e2c037d24c51e0333b1fad90c61d5526a963446 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 22 May 2019 07:26:32 +0000 Subject: [PATCH] gimple-fold.c (arith_code_with_undefined_signed_overflow): Add ABS_EXPR. 2019-05-22 Richard Biener * gimple-fold.c (arith_code_with_undefined_signed_overflow): Add ABS_EXPR. (rewrite_to_defined_overflow): Handle rewriting ABS_EXPR as ABSU_EXPR. * gcc.dg/tree-ssa/ssa-lim-13.c: New testcase. From-SVN: r271501 --- gcc/ChangeLog | 7 +++ gcc/gimple-fold.c | 16 ++++--- gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c | 53 ++++++++++++++++++++++ 4 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 35242bc329c..310f62882a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-05-22 Richard Biener + + * gimple-fold.c (arith_code_with_undefined_signed_overflow): + Add ABS_EXPR. + (rewrite_to_defined_overflow): Handle rewriting ABS_EXPR + as ABSU_EXPR. + 2019-05-22 Alan Modra * config/rs6000/rs6000.h (ASM_OPT_ANY): Define. diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 1b10bae55ca..b3e931744f8 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -7329,6 +7329,7 @@ arith_code_with_undefined_signed_overflow (tree_code code) { switch (code) { + case ABS_EXPR: case PLUS_EXPR: case MINUS_EXPR: case MULT_EXPR: @@ -7361,12 +7362,15 @@ rewrite_to_defined_overflow (gimple *stmt) tree lhs = gimple_assign_lhs (stmt); tree type = unsigned_type_for (TREE_TYPE (lhs)); gimple_seq stmts = NULL; - for (unsigned i = 1; i < gimple_num_ops (stmt); ++i) - { - tree op = gimple_op (stmt, i); - op = gimple_convert (&stmts, type, op); - gimple_set_op (stmt, i, op); - } + if (gimple_assign_rhs_code (stmt) == ABS_EXPR) + gimple_assign_set_rhs_code (stmt, ABSU_EXPR); + else + for (unsigned i = 1; i < gimple_num_ops (stmt); ++i) + { + tree op = gimple_op (stmt, i); + op = gimple_convert (&stmts, type, op); + gimple_set_op (stmt, i, op); + } gimple_assign_set_lhs (stmt, make_ssa_name (type, stmt)); if (gimple_assign_rhs_code (stmt) == POINTER_PLUS_EXPR) gimple_assign_set_rhs_code (stmt, PLUS_EXPR); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 801e5ea57e7..5fbb80c052e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-05-22 Richard Biener + + * gcc.dg/tree-ssa/ssa-lim-13.c: New testcase. + 2019-05-22 Hans-Peter Nilsson PR middle-end/90553 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c new file mode 100644 index 00000000000..65aa7457704 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-13.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fgimple -fdump-tree-lim2-details" } */ + +int __GIMPLE (ssa,startwith("lim")) +foo (int x, int n) +{ + int i; + int r; + int _1; + int _2; + int _6; + + __BB(2): + goto __BB7; + + __BB(3): + if (i_5 == 17) + goto __BB8; + else + goto __BB4; + + __BB(4): + _1 = i_5 & 1; + if (_1 != 0) + goto __BB5; + else + goto __BB6; + + __BB(5): + _2 = __ABS x_8(D); + r_9 = _2 / 5; + goto __BB6; + + __BB(6): + r_3 = __PHI (__BB5: r_9, __BB4: r_4); + i_10 = i_5 + 1; + goto __BB7; + + __BB(7,loop_header(1)): + r_4 = __PHI (__BB2: 1, __BB6: r_3); + i_5 = __PHI (__BB2: 0, __BB6: i_10); + if (i_5 < n_7(D)) + goto __BB3; + else + goto __BB8; + + __BB(8): + _6 = __PHI (__BB3: 0, __BB7: r_4); + return _6; +} + +/* { dg-final { scan-tree-dump-times "Moving statement" 2 "lim2" } } */ +/* { dg-final { scan-tree-dump "ABSU_EXPR" "lim2" } } */ -- 2.30.2