https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122534
--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Uroš Bizjak from comment #1)
> So, simply swap operands in ix86_canonicalize_comparison when MEM operand is
> in the wrong place:
Eh, this one:
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 6b6febc8870..266f89e2bf2 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -598,6 +598,15 @@ ix86_canonicalize_comparison (int *code, rtx *op0, rtx
*op1,
}
}
+ /* Canonicalize TEST operation. */
+ if (!op0_preserve_value
+ && GET_CODE (*op0) == AND
+ && MEM_P (XEXP (*op0, 1)))
+ {
+ std::swap (XEXP (*op0, 0), XEXP (*op0, 1));
+ return;
+ }
+
/* SUB (a, b) underflows precisely when a < b. Convert
(compare (minus (a b)) a) to (compare (a b))
to match *sub<mode>_3 pattern. */