[llvm] [GlobalISel] Fold Add Shift combine from SelectionDAG (PR #177371)
Osman Yasar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 11:57:38 PST 2026
================
@@ -1926,6 +1926,27 @@ def integer_reassoc_combines: GICombineGroup<[
AMinusC1PlusC2
]>;
+// fold (A+(shl (0-B), C)) -> (A-(shl B, C))
+// fold ((shl (0-B), C)+A) -> (A-(shl B, C))
+def add_shl_neg_frags : GICombinePatFrag<
+ (outs root:$dst), (ins $x, $y, $n),
+ [
+ (pattern (G_CONSTANT $zero, 0),
+ (G_SUB $neg_y, $zero, $y),
+ (G_SHL $shl_neg, $neg_y, $n),
+ (G_ADD $dst, $x, $shl_neg)),
+ (pattern (G_CONSTANT $zero, 0),
+ (G_SUB $neg_y, $zero, $y),
+ (G_SHL $shl_neg, $neg_y, $n),
+ (G_ADD $dst, $shl_neg, $x))
+ ]>;
----------------
osmanyasar05 wrote:
Hello, that's a great observation, if both (0-B) and shl(0 - y, n) has multiple uses then the number of instructions would increase, so it looks like they should have hasOneUse checks. Though I believe the original SelectionDAG rewrite does not have a similar check. I will make the required changes.
https://github.com/llvm/llvm-project/pull/177371
More information about the llvm-commits
mailing list