aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Wilson <wilson@cygnus.com>1997-10-26 20:33:27 +0000
committerJeff Law <law@gcc.gnu.org>1997-10-26 13:33:27 -0700
commit7581a30fe2ff49b4e1bf432f6cc5f27efce7ea7e (patch)
tree88ec44b5f1866a21232e71ea7a665d891e885af5
parentedaa4ee0621bfd1747c56e0f77edc72c29510bfe (diff)
downloadgcc-7581a30fe2ff49b4e1bf432f6cc5f27efce7ea7e.zip
gcc-7581a30fe2ff49b4e1bf432f6cc5f27efce7ea7e.tar.gz
gcc-7581a30fe2ff49b4e1bf432f6cc5f27efce7ea7e.tar.bz2
expr.c (expand_expr, [...]): Optimize a reference to an element in a constant string.
* expr.c (expand_expr, case INDIRECT_REF): Optimize a reference to an element in a constant string. From-SVN: r16195
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/expr.c12
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8800542..5cb05f8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+Sun Oct 26 13:31:47 1997 Jim Wilson (wilson@cygnus.com)
+
+ * expr.c (expand_expr, case INDIRECT_REF): Optimize a reference
+ to an element in a constant string.
+
Sun Oct 26 11:41:49 1997 Jason Merrill <jason@yorick.cygnus.com>
* dwarf2out.c (output_call_frame_info): The CIE pointer is now a 32
diff --git a/gcc/expr.c b/gcc/expr.c
index 920ffbc..5cd1b43 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -5406,6 +5406,18 @@ expand_expr (exp, target, tmode, modifier)
{
tree exp1 = TREE_OPERAND (exp, 0);
tree exp2;
+ tree index;
+ tree string = string_constant (exp1, &index);
+ int i;
+
+ if (string
+ && TREE_CODE (string) == STRING_CST
+ && TREE_CODE (index) == INTEGER_CST
+ && !TREE_INT_CST_HIGH (index)
+ && (i = TREE_INT_CST_LOW (index)) < TREE_STRING_LENGTH (string)
+ && GET_MODE_CLASS (mode) == MODE_INT
+ && GET_MODE_SIZE (mode) == 1)
+ return GEN_INT (TREE_STRING_POINTER (string)[i]);
op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
op0 = memory_address (mode, op0);