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

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 13:02:33 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:

https://github.com/llvm/llvm-project/blob/19131c7f36e047898ea954ee5a187ac62f2ab09b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp#L2911
https://github.com/llvm/llvm-project/blob/19131c7f36e047898ea954ee5a187ac62f2ab09b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp#L2936

I noticed it in the other PR. I am strongly against a curated list of opcodes with weaker legalization constraints.

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


More information about the llvm-commits mailing list