From a05c8f23516bdeec9f2bfa3092f031b081405aaa Mon Sep 17 00:00:00 2001
From: Eric Botcazou <ebotcazou@adacore.com>
Date: Tue, 16 Nov 2010 22:30:19 +0000
Subject: [PATCH] re PR rtl-optimization/46490 (ACATS c460007 fails at -O2 or
 above)

	PR rtl-optimization/46490
	* combine.c (expand_compound_operation): Fix thinko.

From-SVN: r166830
---
 gcc/ChangeLog                       |  5 +++++
 gcc/combine.c                       |  6 +++---
 gcc/testsuite/ChangeLog             |  5 +++++
 gcc/testsuite/gnat.dg/opt12.adb     | 18 ++++++++++++++++++
 gcc/testsuite/gnat.dg/opt12_pkg.adb |  8 ++++++++
 gcc/testsuite/gnat.dg/opt12_pkg.ads | 11 +++++++++++
 6 files changed, 50 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gnat.dg/opt12.adb
 create mode 100644 gcc/testsuite/gnat.dg/opt12_pkg.adb
 create mode 100644 gcc/testsuite/gnat.dg/opt12_pkg.ads

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 50f93830b491..30d1e26b151b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+	PR rtl-optimization/46490
+	* combine.c (expand_compound_operation): Fix thinko.
+
 2010-11-16  Richard Henderson  <rth@redhat.com>
 
 	PR target/46470
diff --git a/gcc/combine.c b/gcc/combine.c
index ee26c905d461..d55ce3127d80 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -6761,11 +6761,11 @@ expand_compound_operation (rtx x)
      count.  This can happen in a case like (x >> 31) & 255 on machines
      that can't shift by a constant.  On those machines, we would first
      combine the shift with the AND to produce a variable-position
-     extraction.  Then the constant of 31 would be substituted in to produce
-     a such a position.  */
+     extraction.  Then the constant of 31 would be substituted in
+     to produce such a position.  */
 
   modewidth = GET_MODE_BITSIZE (GET_MODE (x));
-  if (modewidth + len >= pos)
+  if (modewidth >= pos + len)
     {
       enum machine_mode mode = GET_MODE (x);
       tem = gen_lowpart (mode, XEXP (x, 0));
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index afb99ff8f853..10a7c3e61d87 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+	* gnat.dg/opt12.adb: New test.
+	* gnat.dg/opt12_pkg.ad[sb]: New helper.
+
 2010-11-16  Eric Botcazou  <ebotcazou@adacore.com>
 
 	* gcc.target/rx/pack.c: New test.
diff --git a/gcc/testsuite/gnat.dg/opt12.adb b/gcc/testsuite/gnat.dg/opt12.adb
new file mode 100644
index 000000000000..e8b5c4787c62
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt12.adb
@@ -0,0 +1,18 @@
+-- { dg-do run }
+-- { dg-options "-O2" }
+
+with Opt12_Pkg; use Opt12_Pkg;
+
+procedure Opt12 is
+
+   Static_Target : Static_Integer_Subtype;
+
+begin
+
+   Static_Target := Static_Integer_Subtype(Fix_Half);
+
+   if not Equal(Static_Target, 1) then
+     raise Program_Error;
+   end if;
+
+end Opt12;
diff --git a/gcc/testsuite/gnat.dg/opt12_pkg.adb b/gcc/testsuite/gnat.dg/opt12_pkg.adb
new file mode 100644
index 000000000000..646c8734c70f
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt12_pkg.adb
@@ -0,0 +1,8 @@
+package body Opt12_Pkg is
+
+   function Equal (L, R: Static_Integer_Subtype) return Boolean is
+   begin
+      return (L = R);
+   end;
+
+end Opt12_Pkg;
diff --git a/gcc/testsuite/gnat.dg/opt12_pkg.ads b/gcc/testsuite/gnat.dg/opt12_pkg.ads
new file mode 100644
index 000000000000..4defe2b77c7c
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/opt12_pkg.ads
@@ -0,0 +1,11 @@
+package Opt12_Pkg is
+
+   type Static_Integer_Subtype is range -32_000 .. 32_000;
+
+   function Equal (L, R: Static_Integer_Subtype) return Boolean;
+
+   type My_Fixed is delta 0.1 range -5.0 .. 5.0;
+
+   Fix_Half : My_Fixed := 0.5;
+
+end Opt12_Pkg;
-- 
GitLab