[llvm] [DAGCombiner] Set disjoint flag in add->or and xor->or combines (PR #86925)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 28 02:27:34 PDT 2024
https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/86925
We check DAG.haveNoCommonBitsSet so the operands will be known to be disjoint.
I couldn't think of a codegen test case since most targets aren't checking hasDisjoint yet, apart from RISCV in the or_is_add pattern, but it also falls back to computeKnownBits.
>From a9fb7368da4220e35e97257bfcb3d6d895f23289 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 28 Mar 2024 16:36:04 +0800
Subject: [PATCH] [DAGCombiner] Set disjoint flag in add->or and xor->or
combines
We check DAG.haveNoCommonBitsSet so the operands will be known to be disjoint.
I couldn't think of a codegen test case since most targets aren't checking hasDisjoint yet, apart from RISCV in the or_is_add pattern, but it also falls back to computeKnownBits.
---
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 36abe27d262176..6dd3fbb3c97e0c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2887,8 +2887,11 @@ SDValue DAGCombiner::visitADD(SDNode *N) {
// fold (a+b) -> (a|b) iff a and b share no bits.
if ((!LegalOperations || TLI.isOperationLegal(ISD::OR, VT)) &&
- DAG.haveNoCommonBitsSet(N0, N1))
- return DAG.getNode(ISD::OR, DL, VT, N0, N1);
+ DAG.haveNoCommonBitsSet(N0, N1)) {
+ SDNodeFlags Flags;
+ Flags.setDisjoint(true);
+ return DAG.getNode(ISD::OR, DL, VT, N0, N1, Flags);
+ }
// Fold (add (vscale * C0), (vscale * C1)) to (vscale * (C0 + C1)).
if (N0.getOpcode() == ISD::VSCALE && N1.getOpcode() == ISD::VSCALE) {
@@ -9289,8 +9292,11 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
// fold (a^b) -> (a|b) iff a and b share no bits.
if ((!LegalOperations || TLI.isOperationLegal(ISD::OR, VT)) &&
- DAG.haveNoCommonBitsSet(N0, N1))
- return DAG.getNode(ISD::OR, DL, VT, N0, N1);
+ DAG.haveNoCommonBitsSet(N0, N1)) {
+ SDNodeFlags Flags;
+ Flags.setDisjoint(true);
+ return DAG.getNode(ISD::OR, DL, VT, N0, N1, Flags);
+ }
// look for 'add-like' folds:
// XOR(N0,MIN_SIGNED_VALUE) == ADD(N0,MIN_SIGNED_VALUE)
More information about the llvm-commits
mailing list