[llvm] b34a8b3 - [RISCV] Generalize combineAddOfBooleanXor to support any boolean not just setcc.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 25 09:08:25 PDT 2023
Author: Craig Topper
Date: 2023-07-25T09:04:49-07:00
New Revision: b34a8b3a5207965f13fd3a700bad612a3afe5867
URL: https://github.com/llvm/llvm-project/commit/b34a8b3a5207965f13fd3a700bad612a3afe5867
DIFF: https://github.com/llvm/llvm-project/commit/b34a8b3a5207965f13fd3a700bad612a3afe5867.diff
LOG: [RISCV] Generalize combineAddOfBooleanXor to support any boolean not just setcc.
Instead of checking for setcc, look for any 0/1 value.
Reviewed By: asb
Differential Revision: https://reviews.llvm.org/D156153
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 4fd3caf52a0069..76f0ff3ad41ccf 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -10571,7 +10571,7 @@ static SDValue transformAddImmMulImm(SDNode *N, SelectionDAG &DAG,
return DAG.getNode(ISD::ADD, DL, VT, New1, DAG.getConstant(CB, DL, VT));
}
-// Try to turn (add (xor (setcc X, Y), 1) -1) into (neg (setcc X, Y)).
+// Try to turn (add (xor bool, 1) -1) into (neg bool).
static SDValue combineAddOfBooleanXor(SDNode *N, SelectionDAG &DAG) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
@@ -10582,9 +10582,13 @@ static SDValue combineAddOfBooleanXor(SDNode *N, SelectionDAG &DAG) {
if (!isAllOnesConstant(N1))
return SDValue();
- // Look for an (xor (setcc X, Y), 1).
- if (N0.getOpcode() != ISD::XOR || !isOneConstant(N0.getOperand(1)) ||
- N0.getOperand(0).getOpcode() != ISD::SETCC)
+ // Look for (xor X, 1).
+ if (N0.getOpcode() != ISD::XOR || !isOneConstant(N0.getOperand(1)))
+ return SDValue();
+
+ // First xor input should be 0 or 1.
+ APInt Mask = APInt::getBitsSetFrom(VT.getSizeInBits(), 1);
+ if (!DAG.MaskedValueIsZero(N0.getOperand(0), Mask))
return SDValue();
// Emit a negate of the setcc.
diff --git a/llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll b/llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
index 527fa6e1867852..9ebc0d2c171ba3 100644
--- a/llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
+++ b/llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
@@ -481,8 +481,7 @@ define i64 @atomicrmw_uinc_wrap_i64(ptr %ptr, i64 %val) {
; RV32I-NEXT: addi a1, a4, 1
; RV32I-NEXT: seqz a2, a1
; RV32I-NEXT: add a3, a5, a2
-; RV32I-NEXT: xori a0, a0, 1
-; RV32I-NEXT: addi a0, a0, -1
+; RV32I-NEXT: neg a0, a0
; RV32I-NEXT: and a2, a0, a1
; RV32I-NEXT: and a3, a0, a3
; RV32I-NEXT: sw a4, 8(sp)
@@ -537,8 +536,7 @@ define i64 @atomicrmw_uinc_wrap_i64(ptr %ptr, i64 %val) {
; RV32IA-NEXT: addi a1, a4, 1
; RV32IA-NEXT: seqz a2, a1
; RV32IA-NEXT: add a3, a5, a2
-; RV32IA-NEXT: xori a0, a0, 1
-; RV32IA-NEXT: addi a0, a0, -1
+; RV32IA-NEXT: neg a0, a0
; RV32IA-NEXT: and a2, a0, a1
; RV32IA-NEXT: and a3, a0, a3
; RV32IA-NEXT: sw a4, 8(sp)
More information about the llvm-commits
mailing list