From: Kugan <kugan.vivekanandarajah@linaro.org>
To: Jakub Jelinek <jakub@redhat.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH 2/2] Enable elimination of zext/sext
Date: Tue, 24 Jun 2014 11:53:00 -0000 [thread overview]
Message-ID: <53A966BF.30806@linaro.org> (raw)
In-Reply-To: <53A9658F.2070304@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 582 bytes --]
Sets proper flags on the SUBREG based on value
range info and enables elimination of zext/sext when possible.
Thanks,
Kugan
gcc/
2014-06-24 Kugan Vivekanandarajah <kuganv@linaro.org>
* gcc/calls.c (precompute_arguments: Check is_promoted_for_type
and set the promoted mode.
(is_promoted_for_type) : New function.
(expand_expr_real_1) : Check is_promoted_for_type
and set the promoted mode.
* gcc/expr.h (is_promoted_for_type) : New function definition.
* gcc/cfgexpand.c (expand_gimple_stmt_1) : Call emit_move_insn if
SUBREG is promoted with SRP_SIGNED_AND_UNSIGNED.
[-- Attachment #2: p2.txt --]
[-- Type: text/plain, Size: 4620 bytes --]
diff --git a/gcc/calls.c b/gcc/calls.c
index c1fe3b8..4ef9df8 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -1484,7 +1484,10 @@ precompute_arguments (int num_actuals, struct arg_data *args)
args[i].initial_value
= gen_lowpart_SUBREG (mode, args[i].value);
SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1;
- SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
+ if (is_promoted_for_type (args[i].tree_value, mode, !args[i].unsignedp))
+ SUBREG_PROMOTED_SET (args[i].initial_value, SRP_SIGNED_AND_UNSIGNED);
+ else
+ SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp);
}
}
}
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index e8cd87f..0540b4d 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -3309,7 +3309,13 @@ expand_gimple_stmt_1 (gimple stmt)
GET_MODE (target), temp, unsignedp);
}
- convert_move (SUBREG_REG (target), temp, unsignedp);
+ if ((SUBREG_PROMOTED_GET (target) == SRP_SIGNED_AND_UNSIGNED)
+ && (GET_CODE (temp) == SUBREG)
+ && (GET_MODE (target) == GET_MODE (temp))
+ && (GET_MODE (SUBREG_REG (target)) == GET_MODE (SUBREG_REG (temp))))
+ emit_move_insn (SUBREG_REG (target), SUBREG_REG (temp));
+ else
+ convert_move (SUBREG_REG (target), temp, unsignedp);
}
else if (nontemporal && emit_storent_insn (target, temp))
;
diff --git a/gcc/expr.c b/gcc/expr.c
index a8db9f5..b2c8146 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -9209,6 +9209,59 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode,
}
#undef REDUCE_BIT_FIELD
+/* Return TRUE if value in SSA is already zero/sign extended for lhs type
+ (type here is the combination of LHS_MODE and LHS_UNS) using value range
+ information stored. Return FALSE otherwise. */
+bool
+is_promoted_for_type (tree ssa, enum machine_mode lhs_mode, bool lhs_uns)
+{
+ wide_int type_min, type_max;
+ wide_int min, max, limit;
+ unsigned int prec;
+ tree lhs_type;
+ bool rhs_uns;
+
+ if (flag_wrapv
+ || (flag_strict_overflow == false)
+ || (ssa == NULL_TREE)
+ || (TREE_CODE (ssa) != SSA_NAME)
+ || !INTEGRAL_TYPE_P (TREE_TYPE (ssa))
+ || POINTER_TYPE_P (TREE_TYPE (ssa)))
+ return false;
+
+ /* Return FALSE if value_range is not recorded for SSA. */
+ if (get_range_info (ssa, &min, &max) != VR_RANGE)
+ return false;
+
+ lhs_type = lang_hooks.types.type_for_mode (lhs_mode, lhs_uns);
+ rhs_uns = TYPE_UNSIGNED (TREE_TYPE (ssa));
+ prec = min.get_precision ();
+
+ /* Signed maximum value. */
+ limit = wide_int::from (TYPE_MAX_VALUE (TREE_TYPE (ssa)), prec, SIGNED);
+
+ /* Signedness of LHS and RHS differs but values in range. */
+ if ((rhs_uns != lhs_uns)
+ && ((!lhs_uns && !wi::neg_p (min, TYPE_SIGN (lhs_type)))
+ || (lhs_uns && (wi::cmp (max, limit, TYPE_SIGN (TREE_TYPE (ssa))) == -1))))
+ lhs_uns = !lhs_uns;
+
+ /* Signedness of LHS and RHS should match. */
+ if (rhs_uns != lhs_uns)
+ return false;
+
+ type_min = wide_int::from (TYPE_MIN_VALUE (lhs_type), prec, TYPE_SIGN (TREE_TYPE (ssa)));
+ type_max = wide_int::from (TYPE_MAX_VALUE (lhs_type), prec, TYPE_SIGN (TREE_TYPE (ssa)));
+
+ /* Check if values lies in-between the type range. */
+ if ((wi::neg_p (max, TYPE_SIGN (TREE_TYPE (ssa)))
+ || (wi::cmp (max, type_max, TYPE_SIGN (TREE_TYPE (ssa))) != 1))
+ && (!wi::neg_p (min, TYPE_SIGN (TREE_TYPE (ssa)))
+ || (wi::cmp (type_min, min, TYPE_SIGN (TREE_TYPE (ssa))) != 1)))
+ return true;
+
+ return false;
+}
/* Return TRUE if expression STMT is suitable for replacement.
Never consider memory loads as replaceable, because those don't ever lead
@@ -9512,7 +9565,10 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
temp = gen_lowpart_SUBREG (mode, decl_rtl);
SUBREG_PROMOTED_VAR_P (temp) = 1;
- SUBREG_PROMOTED_SET (temp, unsignedp);
+ if (is_promoted_for_type (ssa_name, mode, !unsignedp))
+ SUBREG_PROMOTED_SET (temp, SRP_SIGNED_AND_UNSIGNED);
+ else
+ SUBREG_PROMOTED_SET (temp, unsignedp);
return temp;
}
diff --git a/gcc/expr.h b/gcc/expr.h
index 6a1d3ab..e99d000 100644
--- a/gcc/expr.h
+++ b/gcc/expr.h
@@ -440,6 +440,7 @@ extern rtx expand_expr_real_1 (tree, rtx, enum machine_mode,
enum expand_modifier, rtx *, bool);
extern rtx expand_expr_real_2 (sepops, rtx, enum machine_mode,
enum expand_modifier);
+extern bool is_promoted_for_type (tree, enum machine_mode, bool);
/* Generate code for computing expression EXP.
An rtx for the computed value is returned. The value is never null.
next prev parent reply other threads:[~2014-06-24 11:53 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-24 11:48 [PATCH 0/2] Zext/sext elimination using value range Kugan
2014-06-24 11:51 ` [PATCH 1/2] Enable setting sign and unsigned promoted mode (SPR_SIGNED_AND_UNSIGNED) Kugan
2014-06-24 12:18 ` Jakub Jelinek
2014-06-25 7:21 ` Kugan
2014-06-25 7:50 ` Jakub Jelinek
2014-06-26 1:06 ` Kugan
2014-06-26 2:48 ` Kugan
2014-06-26 5:50 ` Jakub Jelinek
2014-06-26 9:41 ` Kugan
2014-06-26 10:12 ` Jakub Jelinek
2014-06-26 10:42 ` Jakub Jelinek
2014-07-01 8:21 ` Kugan
2014-07-07 6:52 ` Kugan
2014-07-07 8:06 ` Jakub Jelinek
2014-06-26 10:25 ` Andreas Schwab
2014-07-01 8:28 ` Kugan
2014-06-24 11:53 ` Kugan [this message]
2014-06-24 12:21 ` [PATCH 2/2] Enable elimination of zext/sext Jakub Jelinek
2014-06-25 8:15 ` Kugan
2014-06-25 8:36 ` Jakub Jelinek
2014-07-07 6:55 ` Kugan
2014-07-10 12:15 ` Richard Biener
2014-07-11 11:52 ` Kugan
2014-07-11 12:47 ` Richard Biener
2014-07-14 2:58 ` Kugan
2014-07-14 20:11 ` Bernhard Reutner-Fischer
2014-07-23 14:22 ` Richard Biener
2014-08-01 4:51 ` Kugan
2014-08-01 11:16 ` Richard Biener
2014-08-01 16:04 ` Kugan
2014-08-03 23:56 ` Kugan
2014-08-05 14:18 ` Richard Biener
2014-08-05 14:21 ` Jakub Jelinek
2014-08-06 12:09 ` Richard Biener
2014-08-06 13:22 ` Kugan
2014-08-06 13:29 ` Richard Biener
2014-08-07 5:25 ` Kugan
2014-08-07 8:09 ` Richard Biener
2014-08-27 10:01 Uros Bizjak
2014-08-27 10:07 ` Richard Biener
2014-08-27 10:32 ` Uros Bizjak
2014-08-27 10:32 ` Richard Biener
2014-09-01 8:48 ` Jakub Jelinek
2014-09-01 8:54 ` Uros Bizjak
2014-08-28 7:50 ` Kugan
2014-08-28 8:57 ` Richard Biener
2014-09-04 3:41 ` Kugan
2014-09-04 13:00 ` Richard Biener
2014-09-05 1:33 ` Kugan
2014-09-05 9:51 ` Richard Biener
2014-09-07 9:51 ` Kugan
2014-09-08 9:48 ` Richard Biener
2014-09-09 10:06 ` Kugan
2014-09-09 10:28 ` Richard Biener
2014-08-27 13:02 ` Kugan
2014-08-28 3:46 ` Kugan
2014-08-28 6:44 ` Marc Glisse
2014-08-28 7:29 ` Kugan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53A966BF.30806@linaro.org \
--to=kugan.vivekanandarajah@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).