[llvm] [GlobalISel] Combine [a, s, z]ext of undef into 0 or undef (PR #117439)

Amara Emerson via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 24 14:32:10 PST 2024


================
@@ -1857,6 +1857,27 @@ class integer_of_opcode<Instruction castOpcode> : GICombineRule <
 
 def integer_of_truncate : integer_of_opcode<G_TRUNC>;
 
+def anyext_undef: GICombineRule<
+   (defs root:$root),
+   (match (G_IMPLICIT_DEF $undef),
+          (G_ANYEXT $root, $undef):$Aext,
+   [{ return Helper.isUndefLegalOrBeforeLegalizer(MRI.getType(${Aext}->getOperand(0).getReg())); }]),
+   (apply [{ Helper.replaceInstWithUndef(*${Aext}); }])>;
----------------
aemerson wrote:

I don't think this is necessary, it was fine where it was in propagate_undef_any_op.

There are two possible situations w.r.t legality here:
1) We're before legalizer, in which case nothing matters and we can run the combine.
2) We're post-legalizer. However for undef, since we already agreed that having any legal register definition must imply that G_IMPLICIT_DEF is also legal, then we don't need to check for legality here anyway, since G_ANYEXT defines a vreg with the same type as the new undef instruction.

https://github.com/llvm/llvm-project/pull/117439


More information about the llvm-commits mailing list