]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Force operand 1 of bswapsi2 to a register for !TARGET_BSWAP [PR115321]
authorUros Bizjak <ubizjak@gmail.com>
Mon, 3 Jun 2024 13:48:18 +0000 (15:48 +0200)
committerUros Bizjak <ubizjak@gmail.com>
Mon, 3 Jun 2024 13:49:45 +0000 (15:49 +0200)
PR target/115321

gcc/ChangeLog:

* config/i386/i386.md (bswapsi2): Force operand 1
to a register also for !TARGET_BSWAP.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr115321.c: New test.

gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/pr115321.c [new file with mode: 0644]

index 2c95395b7be7255e0434d5905c8f1b74fff3a821..ef83984d00e821ff0efa8260c733fb34bcd1b6ae 100644 (file)
        (bswap:SI (match_operand:SI 1 "nonimmediate_operand")))]
   ""
 {
-  if (TARGET_MOVBE)
-    ;
-  else if (TARGET_BSWAP)
-    operands[1] = force_reg (SImode, operands[1]);
-  else
+  if (!TARGET_MOVBE)
     {
-      rtx x = gen_reg_rtx (SImode);
+      operands[1] = force_reg (SImode, operands[1]);
 
-      emit_insn (gen_bswaphisi2_lowpart (x, operands[1]));
-      emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
-      emit_insn (gen_bswaphisi2_lowpart (operands[0], x));
-      DONE;
+      if (!TARGET_BSWAP)
+       {
+         rtx x = gen_reg_rtx (SImode);
+
+         emit_insn (gen_bswaphisi2_lowpart (x, operands[1]));
+         emit_insn (gen_rotlsi3 (x, x, GEN_INT (16)));
+         emit_insn (gen_bswaphisi2_lowpart (operands[0], x));
+         DONE;
+       }
     }
 })
 
diff --git a/gcc/testsuite/gcc.target/i386/pr115321.c b/gcc/testsuite/gcc.target/i386/pr115321.c
new file mode 100644 (file)
index 0000000..0ddab9b
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile { target ia32 } } */
+/* { dg-options "-march=i386" } */
+
+unsigned foo (unsigned x) { return __builtin_bswap32 (x); }