From d0e4968c33c257bcfa1afa4f499661c18c80e5bc Mon Sep 17 00:00:00 2001
From: David Daney <ddaney@caviumnetworks.com>
Date: Fri, 4 Dec 2009 17:46:23 +0000
Subject: [PATCH] re PR rtl-optimization/42164 (internal compiler error: in
 simplify_subreg, at simplify-rtx.c:5138)

2009-12-04  David Daney  <ddaney@caviumnetworks.com>

	PR rtl-optimization/42164
	* combine.c (combine_simplify_rtx): Handle truncation of integer
	constants.

2009-12-04  David Daney  <ddaney@caviumnetworks.com>

	PR rtl-optimization/42164
	* gcc.c-torture/compile/pr42164.c: New test.

From-SVN: r154987
---
 gcc/ChangeLog                                 |  6 +++++
 gcc/combine.c                                 |  4 +++
 gcc/testsuite/ChangeLog                       |  5 ++++
 gcc/testsuite/gcc.c-torture/compile/pr42164.c | 25 +++++++++++++++++++
 4 files changed, 40 insertions(+)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr42164.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 450d54d62740..f01968c789c0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2009-12-04  David Daney  <ddaney@caviumnetworks.com>
+
+	PR rtl-optimization/42164
+	* combine.c (combine_simplify_rtx): Handle truncation of integer
+	constants.
+
 2009-12-04  Richard Guenther  <rguenther@suse.de>
 
 	* lto-streamer-out.c (pack_ts_decl_common_value_fields):
diff --git a/gcc/combine.c b/gcc/combine.c
index cdc677d17c73..7f3f6da2cea1 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -5156,6 +5156,10 @@ combine_simplify_rtx (rtx x, enum machine_mode op0_mode, int in_dest)
 	       force_to_mode (XEXP (x, 0), GET_MODE (XEXP (x, 0)),
 			      GET_MODE_MASK (mode), 0));
 
+      /* We can truncate a constant value and return it.  */
+      if (CONST_INT_P (XEXP (x, 0)))
+	return gen_int_mode (INTVAL (XEXP (x, 0)), mode);
+
       /* Similarly to what we do in simplify-rtx.c, a truncate of a register
 	 whose value is a comparison can be replaced with a subreg if
 	 STORE_FLAG_VALUE permits.  */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 577d18b21633..b20ddd2fdcf5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2009-12-04  David Daney  <ddaney@caviumnetworks.com>
+
+	PR rtl-optimization/42164
+	* gcc.c-torture/compile/pr42164.c: New test.
+
 2009-12-04  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* gnat.dg/specs/size_attribute1.ads: New test.
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr42164.c b/gcc/testsuite/gcc.c-torture/compile/pr42164.c
new file mode 100644
index 000000000000..7b94aefe7d83
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr42164.c
@@ -0,0 +1,25 @@
+typedef struct
+{
+  unsigned long long pte;
+} pte_t;
+pte_t mk_swap_pte (unsigned long offset)
+{
+  pte_t pte;
+  pte.pte = (offset << 40);
+  return pte;
+}
+int pte_file (pte_t pte)
+{
+  return pte.pte & (1 << 4);
+}
+typedef struct
+{
+  unsigned long val;
+} swp_entry_t;
+pte_t swp_entry_to_pte (swp_entry_t entry)
+{
+  swp_entry_t arch_entry;
+  arch_entry = (swp_entry_t){mk_swap_pte (swp_offset (entry)).pte};
+  __BUG_ON ((unsigned long) pte_file ((pte_t) {arch_entry.val}));
+  return (pte_t) {arch_entry.val};
+}
-- 
GitLab