]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
xtensa: Fix B[GE/LT]UI instructions with immediate values of 32768 or 65536 not being...
authorTakayuki 'January June' Suwa <jjsuwa_sys3175@yahoo.co.jp>
Mon, 7 Jul 2025 14:40:17 +0000 (23:40 +0900)
committerMax Filippov <jcmvbkbc@gmail.com>
Tue, 8 Jul 2025 17:28:48 +0000 (10:28 -0700)
This is because in canonicalize_comparison() in gcc/expmed.cc, the COMPARE
rtx_cost() for the immediate values in the title does not change between
the old and new versions.  This patch fixes that.

(note: Currently, this patch only works if some constant propagation
optimizations are enabled (-O2 or higher) or if bare large constant
assignments are possible (-mconst16 or -mauto-litpools).  In the future
I hope to make it work at -O1...)

gcc/ChangeLog:

* config/xtensa/xtensa.cc (xtensa_b4const_or_zero):
Remove.
(xtensa_b4const): Add a case where the value is 0, and rename
to xtensa_b4const_or_zero.
(xtensa_rtx_costs): Fix to also consider the result of
xtensa_b4constu().

gcc/testsuite/ChangeLog:

* gcc.target/xtensa/BGEUI-BLTUI-32k-64k.c: New.

gcc/config/xtensa/xtensa.cc
gcc/testsuite/gcc.target/xtensa/BGEUI-BLTUI-32k-64k.c [new file with mode: 0644]

index 8c43a69f4cd9a02f51a37d098060417c6f63d7f9..b75cec13b28ad1ce3ebd75f80ab1c53a321b70d4 100644 (file)
@@ -423,12 +423,13 @@ xtensa_uimm8x4 (HOST_WIDE_INT v)
 }
 
 
-static bool
-xtensa_b4const (HOST_WIDE_INT v)
+bool
+xtensa_b4const_or_zero (HOST_WIDE_INT v)
 {
   switch (v)
     {
     case -1:
+    case 0:
     case 1:
     case 2:
     case 3:
@@ -450,15 +451,6 @@ xtensa_b4const (HOST_WIDE_INT v)
 }
 
 
-bool
-xtensa_b4const_or_zero (HOST_WIDE_INT v)
-{
-  if (v == 0)
-    return true;
-  return xtensa_b4const (v);
-}
-
-
 bool
 xtensa_b4constu (HOST_WIDE_INT v)
 {
@@ -4512,7 +4504,8 @@ xtensa_rtx_costs (rtx x, machine_mode mode, int outer_code,
            }
          break;
        case COMPARE:
-         if ((INTVAL (x) == 0) || xtensa_b4const (INTVAL (x)))
+         if (xtensa_b4const_or_zero (INTVAL (x))
+             || xtensa_b4constu (INTVAL (x)))
            {
              *total = 0;
              return true;
diff --git a/gcc/testsuite/gcc.target/xtensa/BGEUI-BLTUI-32k-64k.c b/gcc/testsuite/gcc.target/xtensa/BGEUI-BLTUI-32k-64k.c
new file mode 100644 (file)
index 0000000..05873b8
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+extern void foo(void);
+
+void BGEUI_test(unsigned int a)
+{
+  if (a < 32768U)
+    foo();
+}
+
+void BLTUI_test(unsigned int a)
+{
+  if (a >= 65536U)
+    foo();
+}
+
+/* { dg-final { scan-assembler-times "bgeui" 1 } } */
+/* { dg-final { scan-assembler-times "bltui" 1 } } */