From 756191b7c51263603b91b45f60d5d6acf7250711 Mon Sep 17 00:00:00 2001
From: Joseph Myers <joseph@codesourcery.com>
Date: Sat, 19 Nov 2005 12:32:23 +0000
Subject: [PATCH] combine.c (make_compound_operation): Swap operands of
 commutative operation if necessary before returning.

	* combine.c (make_compound_operation): Swap operands of
	commutative operation if necessary before returning.

From-SVN: r107219
---
 gcc/ChangeLog |  5 +++++
 gcc/combine.c | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 1200433e317e..21b558572606 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2005-11-19  Joseph S. Myers  <joseph@codesourcery.com>
+
+	* combine.c (make_compound_operation): Swap operands of
+	commutative operation if necessary before returning.
+
 2005-11-19  Richard Guenther  <rguenther@suse.de>
 
 	PR middle-end/23294
diff --git a/gcc/combine.c b/gcc/combine.c
index 9f910a7b336e..b43b9b621c66 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -6914,6 +6914,16 @@ make_compound_operation (rtx x, enum rtx_code in_code)
 	SUBST (XEXP (x, i), new);
       }
 
+  /* If this is a commutative operation, the changes to the operands
+     may have made it noncanonical.  */
+  if (COMMUTATIVE_ARITH_P (x)
+      && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
+    {
+      tem = XEXP (x, 0);
+      SUBST (XEXP (x, 0), XEXP (x, 1));
+      SUBST (XEXP (x, 1), tem);
+    }
+
   return x;
 }
 
-- 
GitLab