[llvm] [GlobalISel] Migrate remaining generic wip_match_opcode combines to MIR-pattern. (PR #222851)
Vikash Gupta via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 02:56:44 PDT 2026
================
@@ -1287,12 +1418,30 @@ def xor_of_and_with_same_reg: GICombineRule <
(apply [{ Helper.applyXorOfAndWithSameReg(*${root}, ${matchinfo}); }])
>;
-// Transform (ptr_add 0, x) -> (int_to_ptr x)
-def ptr_add_with_zero: GICombineRule<
+// Transform scalar (ptr_add 0, x) -> (int_to_ptr x).
+// Skip a constant offset so const_ptradd_to_i2p / constant_fold_binop can fold
+// (ptr_add 0, C) to a pointer G_CONSTANT instead of G_INTTOPTR of an integer.
+def ptr_add_with_zero_scalar: GICombineRule<
+ (defs root:$root),
+ (match (G_PTR_ADD $dst, 0, $offset):$root,
----------------
vg0204 wrote:
The literal `0` is matched by isOperandImmEqual → getIConstantVRegValWithLookThrough, which looks through G_INTTOPTR. The old matchPtrAddZero also used getIConstantVRegVal and did not look through anything, but G_INTTOPTR(G_CONSTANT 0) still folds.
Just added `add_nullptr_inttoptr` in `AMDGPU/GlobalISel/combine-add-nullptr.mir` to justify it!
https://github.com/llvm/llvm-project/pull/222851
More information about the llvm-commits
mailing list