+2016-10-05 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/77826
+ * genmatch.c (dt_operand::gen_match_op): Amend operand_equal_p
+ with types_match for GIMPLE code gen to handle type mismatched
+ constants properly.
+ (dt_operand::gen): Adjust.
+ * match.pd ((X /[ex] A) * A -> X): Properly handle converted
+ and constant A.
+
2016-10-05 Richard Biener <rguenther@suse.de>
* match.pd (copysign(x, CST) -> [-]abs (x)): New pattern.
void gen (FILE *, int, bool);
unsigned gen_predicate (FILE *, int, const char *, bool);
- unsigned gen_match_op (FILE *, int, const char *);
+ unsigned gen_match_op (FILE *, int, const char *, bool);
unsigned gen_gimple_expr (FILE *, int);
unsigned gen_generic_expr (FILE *, int, const char *);
a capture-match. */
unsigned
-dt_operand::gen_match_op (FILE *f, int indent, const char *opname)
+dt_operand::gen_match_op (FILE *f, int indent, const char *opname, bool gimple)
{
char match_opname[20];
match_dop->get_name (match_opname);
- fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n",
- opname, match_opname, opname, match_opname);
+ if (gimple)
+ fprintf_indent (f, indent, "if (%s == %s || (operand_equal_p (%s, %s, 0) "
+ "&& types_match (%s, %s)))\n",
+ opname, match_opname, opname, match_opname,
+ opname, match_opname);
+ else
+ fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n",
+ opname, match_opname, opname, match_opname);
fprintf_indent (f, indent + 2, "{\n");
return 1;
}
else if (type == DT_TRUE)
;
else if (type == DT_MATCH)
- n_braces = gen_match_op (f, indent, opname);
+ n_braces = gen_match_op (f, indent, opname, gimple);
else
gcc_unreachable ();
/* (X /[ex] A) * A -> X. */
(simplify
- (mult (convert? (exact_div @0 @1)) @1)
- /* Look through a sign-changing conversion. */
- (convert @0))
+ (mult (convert1? (exact_div @0 @1)) (convert2? @2))
+ /* We cannot use matching captures here, since in the case of
+ constants we don't see the second conversion. Look through
+ a sign-changing or widening conversions. */
+ (if (operand_equal_p (@1, @2, 0)
+ && element_precision (@0) <= element_precision (type))
+ (convert @0)))
/* Canonicalization of binary operations. */