[llvm] [GlobalISel] Combine G_ZEXT of undef -> 0 (PR #113764)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 30 16:07:08 PDT 2024


Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/113764 at github.com>


================
@@ -2916,8 +2916,11 @@ void CombinerHelper::replaceInstWithFConstant(MachineInstr &MI, double C) {
 
 void CombinerHelper::replaceInstWithConstant(MachineInstr &MI, int64_t C) {
   assert(MI.getNumDefs() == 1 && "Expected only one def?");
-  Builder.buildConstant(MI.getOperand(0), C);
-  MI.eraseFromParent();
+  LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
+  if (isConstantLegalOrBeforeLegalizer(DstTy)) {
----------------
arsenm wrote:

I don't see a need for Helper.matchOperandIsUndef any longer. You can directly match a G_IMPLICIT_DEF input in tablegen. The match predicate code would then only need to check the legality of the new G_IMPLICIT_DEF or G_CONSTANT. 

The legality check would always be in the matcher, there shouldn't be any searching to do. 

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


More information about the llvm-commits mailing list