[llvm] [GlobalISel] Combine G_MERGE_VALUES of undef (PR #113381)
Sam Elliott via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 23 07:59:05 PDT 2024
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>,
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/113381 at github.com>
================
@@ -420,7 +420,8 @@ def unary_undef_to_zero: GICombineRule<
// replaced with undef.
def propagate_undef_any_op: GICombineRule<
(defs root:$root),
- (match (wip_match_opcode G_ADD, G_FPTOSI, G_FPTOUI, G_SUB, G_XOR, G_TRUNC, G_BITCAST, G_ANYEXT):$root,
+ (match (wip_match_opcode G_ADD, G_FPTOSI, G_FPTOUI, G_SUB, G_XOR, G_TRUNC, G_BITCAST,
+ G_ANYEXT, G_MERGE_VALUES):$root,
----------------
lenary wrote:
I have no problems with how this has been legalized.
This patch proposes an optimisation that relies on specific semantics of G_MERGE_VALUES and undef - that if any inputs are undef, then the output must be undef. This optimisation produces miscompiles, as the alive2 link shows - so the optimisation must not be correct.
I think that David is right, and the output of G_MERGE_VALUES should only be undef if all inputs are undef (not if any are undef). This reasoning makes sense to me because if you are assembling a wide value by concatenating some defined bits and some undefined bits, then that wide value must still have some defined bits (not be all undefined bits). If you are assembling a wide value by concatenating only undefined bits, then it stands to reason that all the outputs are undefined.
https://github.com/llvm/llvm-project/pull/113381
More information about the llvm-commits
mailing list