[llvm] [GIsel] Add combine (sub a, (mul x, C)) -> (add a, (mul x, -C)) (PR #194282)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 10:14:13 PDT 2026


================
@@ -359,6 +359,17 @@ def sub_to_add : GICombineRule<
          [{ return Helper.matchCombineSubToAdd(*${mi}, ${matchinfo}); }]),
   (apply [{ Helper.applyBuildFnNoErase(*${mi}, ${matchinfo}); }])>;
 
+// Fold (sub a, (mul x, C)) -> (add a, (mul x, -C)), if mul has one use.
+def sub_of_mul_const : GICombineRule<
+  (defs root:$d),
+  (match (G_CONSTANT $c, $imm),
+         (G_MUL $mul, $x, $c),
+         (G_SUB $d, $a, $mul),
+         [{ return MRI.hasOneNonDBGUse(${mul}.getReg()); }]),
----------------
arsenm wrote:

We also should get a proper operator for hasOneUse 

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


More information about the llvm-commits mailing list