[llvm] [GlobalISel][TableGen] Add GIReplaceRegWithConstant/FConstant builtins (PR #222298)

Vikash Gupta via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 00:08:12 PDT 2026


vg0204 wrote:

> I expect to write this as the instruction, not this new special operator

If we do that we need to handle Scalar and vector Dst as separate rules that will look something like this :

```
def undef_to_int_zero_scalar: GICombineRule<`
  (defs root:$dst),
  (match (undef_to_int_zero_frags $dst),
         [{ return MRI.getType(${dst}.getReg()).isScalar(); }]),
  (apply (G_CONSTANT $dst, (GITypeOf<"$dst"> 0)))>;

def undef_to_int_zero_vector: GICombineRule<
  (defs root:$dst),
  (match (undef_to_int_zero_frags $dst),
         [{ return MRI.getType(${dst}.getReg()).isVector(); }]),
  (apply (COPY $dst, (GITypeOf<"$dst"> 0)))>;

def undef_to_int_zero : GICombineGroup<[undef_to_int_zero_scalar,
                                        undef_to_int_zero_vector]>;
```

As for to use `buildConstant` that handles both as used in `replaceInstWithConstant`, we just new GIBuiltin feature that does the same which exactly `GIReplaceRegWithConstant` do here.

Can you explain the any benefit we might get using suggested approach? 

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


More information about the llvm-commits mailing list