diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 63db1eb5696971c5610f3816f2667487aaa8d446..64fe31a0477e09f82d47eee0fc6ddb01b023a803 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2012-11-02  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/55147
+	* config/i386/i386.md (bswapdi2): Limit to TARGET_64BIT.
+	(*bswapdi2_doubleword): Removed.
+
 2012-11-02  Gerald Pfeifer  <gerald@pfeifer.com>
 
 	* doc/install.texi (Specific): Remove moxie web reference.
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 538120c8f2264e275ec42c2d9377a4f393ec1504..61d3ccdd274a6b769bf4f65eb737f6c7cbd56171 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -12669,55 +12669,10 @@
 (define_expand "bswapdi2"
   [(set (match_operand:DI 0 "register_operand")
 	(bswap:DI (match_operand:DI 1 "nonimmediate_operand")))]
-  ""
-{
-  if (TARGET_64BIT && !TARGET_MOVBE)
-    operands[1] = force_reg (DImode, operands[1]);
-})
-
-(define_insn_and_split "*bswapdi2_doubleword"
-  [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m")
-	(bswap:DI
-	  (match_operand:DI 1 "nonimmediate_operand" "0,m,r")))]
-  "!TARGET_64BIT
-   && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
-  "#"
-  "&& reload_completed"
-  [(set (match_dup 2)
-  	(bswap:SI (match_dup 1)))
-   (set (match_dup 0)
-  	(bswap:SI (match_dup 3)))]
+  "TARGET_64BIT"
 {
-  split_double_mode (DImode, &operands[0], 2, &operands[0], &operands[2]);
-
-  if (REG_P (operands[0]) && REG_P (operands[1]))
-    {
-      emit_insn (gen_swapsi (operands[0], operands[2]));
-      emit_insn (gen_bswapsi2 (operands[0], operands[0]));
-      emit_insn (gen_bswapsi2 (operands[2], operands[2]));
-      DONE;
-    }
-
   if (!TARGET_MOVBE)
-    {
-      if (MEM_P (operands[0]))
-	{
-	  emit_insn (gen_bswapsi2 (operands[3], operands[3]));
-	  emit_insn (gen_bswapsi2 (operands[1], operands[1]));
-
-	  emit_move_insn (operands[0], operands[3]);
-	  emit_move_insn (operands[2], operands[1]);
-	}
-      if (MEM_P (operands[1]))
-	{
-	  emit_move_insn (operands[2], operands[1]);
-	  emit_move_insn (operands[0], operands[3]);
-
-	  emit_insn (gen_bswapsi2 (operands[2], operands[2]));
-	  emit_insn (gen_bswapsi2 (operands[0], operands[0]));
-	}
-      DONE;
-    }
+    operands[1] = force_reg (DImode, operands[1]);
 })
 
 (define_expand "bswapsi2"
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 735d1097cd91ed28e63b28400857117590a6408b..b161d58c7e399e09c58243fd1a9e6bca50c81237 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-11-02  Jakub Jelinek  <jakub@redhat.com>
+
+	PR target/55147
+	* gcc.target/i386/pr55147.c: New test.
+
 2012-11-01  David Edelsohn  <dje.gcc@gmail.com>
 
 	* gfortran.dg/default_format_1.f90: XFAIL on AIX.
diff --git a/gcc/testsuite/gcc.target/i386/pr55147.c b/gcc/testsuite/gcc.target/i386/pr55147.c
new file mode 100644
index 0000000000000000000000000000000000000000..5be02f11c02f98f67d0bdd2f2f1f118f6aabfafa
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr55147.c
@@ -0,0 +1,25 @@
+/* PR target/55147 */
+/* { dg-do run } */
+/* { dg-options "-O1" } */
+/* { dg-additional-options "-march=i486" { target ia32 } } */
+
+extern void abort (void);
+
+__attribute__((noclone, noinline)) unsigned int
+foo (unsigned long long *p, int i)
+{
+  return __builtin_bswap64 (p[i]);
+}
+
+int
+main ()
+{
+  unsigned long long p[64];
+  int i;
+  for (i = 0; i < 64; i++)
+    p[i] = 0x123456789abcdef0ULL ^ (1ULL << i) ^ (1ULL << (63 - i));
+  for (i = 0; i < 64; i++)
+    if (foo (p, i) != __builtin_bswap32 (p[i] >> 32))
+      abort ();
+  return 0;
+}