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

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 11:18:30 PDT 2024


================
@@ -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)) {
----------------
tschuett wrote:

We explicitly split it into match and apply. The match function is matching a pattern on the MIR. If it found a pattern, it will return true. Then it is up to the apply function to mutate the IR. Splitting legalization  between match and apply or moving it into match is error prone. The next refactoring will be really bad. The match function is for higher level decisions. I found MIR that looks like sin. apply is for low-level stuff. Let's build it.

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


More information about the llvm-commits mailing list