[PATCH] D156153: [RISCV] Generalize combineAddOfBooleanXor to support any boolean not just setcc.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 10:42:23 PDT 2023
craig.topper created this revision.
craig.topper added reviewers: asb, wangpc, reames, mgudim.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: eopXD, MaskRay.
Herald added a project: LLVM.
Instead of checking for setcc, look for any 0/1 value.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156153
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
Index: llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
===================================================================
--- llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
+++ llvm/test/CodeGen/RISCV/atomicrmw-uinc-udec-wrap.ll
@@ -481,8 +481,7 @@
; 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 @@
; 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)
Index: llvm/lib/Target/RISCV/RISCVISelLowering.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -10533,7 +10533,7 @@
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);
@@ -10544,9 +10544,13 @@
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();
+
+ // 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156153.543635.patch
Type: text/x-patch
Size: 2032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230724/ea689453/attachment.bin>
More information about the llvm-commits
mailing list