From: Kugan <kugan.vivekanandarajah@linaro.org>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: Richard Biener <richard.guenther@gmail.com>
Subject: [4/7] Use correct promoted mode sign for result of GIMPLE_CALL
Date: Mon, 07 Sep 2015 03:01:00 -0000 [thread overview]
Message-ID: <55ECFDB6.8010100@linaro.org> (raw)
In-Reply-To: <55ECFC2A.7050908@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 1155 bytes --]
For the following testcase (compiling with -O1; -O2 works fine), we have
a stmt with stm_code SSA_NAME (_7 = _ 6) and for which _6 is defined by
a GIMPLE_CALL. In this case, we are using wrong SUNREG promoted mode
resulting in wrong code. Simple SSA_NAME copes are generally optimized
but when they are not, we can end up using the wrong promoted mode.
Attached patch fixes when we have one copy. I think it might be better
to do this in a while loop but I don't think it can happen in practice.
Please let me know what you think.
_6 = bar5 (-10);
...
_7 = _6;
_3 = (long unsigned int) _6;
...
if (_3 != l5.0_4)
for
extern void abort (void);
__attribute__ ((noinline))
static unsigned short int foo5 (int x)
{
return x;
}
__attribute__ ((noinline))
short int bar5 (int x)
{
return foo5 (x + 6);
}
unsigned long l5 = (short int) -4;
int
main (void)
{
if (bar5 (-10) != l5)
abort ();
return 0;
}
gcc/ChangeLog:
2015-09-07 Kugan Vivekanandarajah <kuganv@linaro.org>
* expr.c (expand_expr_real_1): Set proper SUNREG_PROMOTED_MODE for
SSA_NAME that was set by GIMPLE_CALL and assigned to another
SSA_NAME of same type.
[-- Attachment #2: 0004-use-correct-promoted-sign-for-result-of-GIMPLE_CALL.patch --]
[-- Type: text/x-diff, Size: 1231 bytes --]
From 64ac68bfda1d3e8487827512e6d163b384e8a1cf Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Wed, 2 Sep 2015 12:18:41 +1000
Subject: [PATCH 4/8] use correct promoted sign for result of GIMPLE_CALL
---
gcc/expr.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/gcc/expr.c b/gcc/expr.c
index bcd87c0..6dac3cf 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -9633,7 +9633,22 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
gimple_call_fntype (g),
2);
else
- pmode = promote_ssa_mode (ssa_name, &unsignedp);
+ {
+ tree rhs;
+ gimple stmt;
+ if (code == SSA_NAME
+ && is_gimple_assign (g)
+ && (rhs = gimple_assign_rhs1 (g))
+ && TREE_CODE (rhs) == SSA_NAME
+ && (stmt = SSA_NAME_DEF_STMT (rhs))
+ && gimple_code (stmt) == GIMPLE_CALL
+ && !gimple_call_internal_p (stmt))
+ pmode = promote_function_mode (type, mode, &unsignedp,
+ gimple_call_fntype (stmt),
+ 2);
+ else
+ pmode = promote_ssa_mode (ssa_name, &unsignedp);
+ }
gcc_assert (GET_MODE (decl_rtl) == pmode);
temp = gen_lowpart_SUBREG (mode, decl_rtl);
--
1.9.1
next prev parent reply other threads:[~2015-09-07 3:00 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-07 2:55 [0/7] Type promotion pass and elimination of zext/sext Kugan
2015-09-07 2:57 ` [1/7] Add new tree code SEXT_EXPR Kugan
2015-09-15 13:20 ` Richard Biener
2015-10-11 10:35 ` Kugan
2015-10-12 12:22 ` Richard Biener
2015-10-15 5:49 ` Kugan
2015-10-21 10:49 ` Richard Biener
2015-09-07 2:58 ` [2/7] Add new type promotion pass Kugan
2015-10-15 5:52 ` Kugan
2015-10-15 22:47 ` Richard Henderson
2015-09-07 3:00 ` [3/7] Optimize ZEXT_EXPR with tree-vrp Kugan
2015-09-15 13:18 ` Richard Biener
2015-10-06 23:12 ` kugan
2015-10-07 8:20 ` Richard Biener
2015-10-07 23:40 ` Kugan
2015-10-09 10:29 ` Richard Biener
2015-10-11 2:56 ` Kugan
2015-10-12 12:13 ` Richard Biener
2015-09-07 3:01 ` Kugan [this message]
2015-09-07 13:16 ` [4/7] Use correct promoted mode sign for result of GIMPLE_CALL Michael Matz
2015-09-08 0:00 ` Kugan
2015-09-08 15:45 ` Jeff Law
2015-09-08 22:09 ` Jim Wilson
2015-09-15 12:51 ` Richard Biener
2015-10-07 1:03 ` kugan
2015-09-07 3:01 ` [5/7] Allow gimple debug stmt in widen mode Kugan
2015-09-07 13:46 ` Michael Matz
2015-09-08 0:01 ` Kugan
2015-09-15 13:02 ` Richard Biener
2015-10-15 5:45 ` Kugan
2015-10-16 9:27 ` Richard Biener
2015-10-18 20:51 ` Kugan
2015-09-07 3:03 ` Kugan
2015-09-07 3:03 ` [6/7] Temporary workaround to get aarch64 bootstrap Kugan
2015-09-07 5:54 ` [7/7] Adjust-arm-test cases Kugan
2015-11-02 11:43 ` Richard Earnshaw
2015-10-20 20:13 ` [0/7] Type promotion pass and elimination of zext/sext Kugan
2015-10-21 12:56 ` Richard Biener
2015-10-21 13:57 ` Richard Biener
2015-10-21 17:17 ` Joseph Myers
2015-10-21 18:11 ` Richard Henderson
2015-10-22 12:48 ` Richard Biener
2015-10-22 11:01 ` Kugan
2015-10-22 14:24 ` Richard Biener
2015-10-27 1:48 ` kugan
2015-10-28 15:51 ` Richard Biener
2015-11-02 9:17 ` Kugan
2015-11-03 14:40 ` Richard Biener
2015-11-08 9:43 ` Kugan
2015-11-10 14:13 ` Richard Biener
2015-11-12 6:08 ` Kugan
2015-11-14 1:15 ` Kugan
2015-11-18 14:04 ` Richard Biener
2015-11-18 15:06 ` Richard Biener
2015-11-24 2:52 ` Kugan
2015-12-10 0:27 ` Kugan
2015-12-16 13:18 ` Richard Biener
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=55ECFDB6.8010100@linaro.org \
--to=kugan.vivekanandarajah@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.guenther@gmail.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).