2011-06-23 Andrew Stubbs <ams@codesourcery.com>
gcc/
* tree-ssa-math-opts.c (convert_mult_to_widen): Better handle
unsigned inputs of different modes.
(convert_plusminus_to_widen): Likewise.
gcc/testsuite/
* gcc.target/arm/smlalbb-3.c: New file.
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv7-a" } */
+
+long long
+foo (long long a, short *b, char *c)
+{
+ return a + *b * *c;
+}
+
+/* { dg-final { scan-assembler "smlalbb" } } */
@@ -2103,9 +2103,17 @@ convert_mult_to_widen (gimple stmt, gimple_stmt_iterator *gsi)
{
if (op != smul_widen_optab)
{
- from_mode = GET_MODE_WIDER_MODE (from_mode);
- if (GET_MODE_SIZE (to_mode) <= GET_MODE_SIZE (from_mode))
- return false;
+ /* We can use a signed multiply with unsigned types as long as
+ there is a wider mode to use, or it is the smaller of the two
+ types that is unsigned. Note that type1 >= type2, always. */
+ if (TYPE_UNSIGNED (type1)
+ || (TYPE_UNSIGNED (type2)
+ && TYPE_MODE (type2) == from_mode))
+ {
+ from_mode = GET_MODE_WIDER_MODE (from_mode);
+ if (GET_MODE_SIZE (to_mode) <= GET_MODE_SIZE (from_mode))
+ return false;
+ }
op = smul_widen_optab;
handler = find_widening_optab_handler_and_mode (op, to_mode,
@@ -2244,14 +2252,21 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt,
if (TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2))
{
enum machine_mode mode = TYPE_MODE (type1);
- mode = GET_MODE_WIDER_MODE (mode);
- if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (TYPE_MODE (type)))
+
+ /* We can use a signed multiply with unsigned types as long as
+ there is a wider mode to use, or it is the smaller of the two
+ types that is unsigned. Note that type1 >= type2, always. */
+ if (TYPE_UNSIGNED (type1)
+ || (TYPE_UNSIGNED (type2)
+ && TYPE_MODE (type2) == mode))
{
- type1 = type2 = lang_hooks.types.type_for_mode (mode, 0);
- cast1 = cast2 = true;
+ mode = GET_MODE_WIDER_MODE (mode);
+ if (GET_MODE_SIZE (mode) >= GET_MODE_SIZE (TYPE_MODE (type)))
+ return false;
}
- else
- return false;
+
+ type1 = type2 = lang_hooks.types.type_for_mode (mode, 0);
+ cast1 = cast2 = true;
}
if (TYPE_MODE (type2) != TYPE_MODE (type1))