From: Robin Dapp Date: Thu, 8 Jan 2026 15:35:52 +0000 (-0700) Subject: Re: [PATCH] match: Check else value compatibility [PR123268]. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a50005a5fdf2bb2534c9bcbbdba77cdad3e3f43;p=thirdparty%2Fgcc.git Re: [PATCH] match: Check else value compatibility [PR123268]. In PR123268 we transform x * { 0 or 1, 0 or 1, ... } into x & { 0 or -1, 0 or -1, ...} which is a match.pd pattern. We start out with vect_b_28.48_48 = .COND_LEN_MUL ({ -1, -1, -1, -1 }, a, b, { 0.0, 0.0, 0.0, 0.0 }, 4, 0); and simplify to _67 = .COND_LEN_AND ({ -1, -1, -1, -1 }, _60, { 4294967295, 0, 0, 0 }, { 0.0, 0.0, 0.0, 0.0 }, 4, 0); where the operation type is int but the else value (that we just copied over from the original op) is still float. In order to catch that, this patch checks if the operation type and the else value type are compatible while reassembling the conditional operation. PR target/123268 gcc/ChangeLog: * gimple-match-exports.cc (convert_conditional_op): Check if orig_op->type and type of else value match. --- diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc index 2f4ac960cb1..5fd1baba7a4 100644 --- a/gcc/gimple-match-exports.cc +++ b/gcc/gimple-match-exports.cc @@ -184,6 +184,13 @@ convert_conditional_op (gimple_match_op *orig_op, for (unsigned int i = 0; i < num_ops; ++i) new_op->ops[i + 1] = orig_op->ops[i]; tree else_value = orig_op->cond.else_value; + /* Some patterns convert operand types, e.g. from float to int. + If we had a real else value before (e.g. float) it won't match + the type. Verify that here. */ + if (else_value + && !types_compatible_p (orig_op->type, TREE_TYPE (else_value))) + return false; + if (!else_value) else_value = targetm.preferred_else_value (ifn, orig_op->type, num_ops, orig_op->ops);