[PATCH] D141884: [DAG] Peek through ZEXT/TRUNC in foldAddSubMasked1
Amaury SECHET via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 16 18:43:45 PST 2023
deadalnix created this revision.
deadalnix added reviewers: RKSimon, craig.topper, efriedma, spatel, lebedev.ri.
Herald added subscribers: StephenFan, ecnelises, pengfei, hiraditya.
Herald added a project: All.
deadalnix requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Fix a regression in D141883 <https://reviews.llvm.org/D141883>
Depends on D141883 <https://reviews.llvm.org/D141883>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141884
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/known-signbits-vector.ll
Index: llvm/test/CodeGen/X86/known-signbits-vector.ll
===================================================================
--- llvm/test/CodeGen/X86/known-signbits-vector.ll
+++ llvm/test/CodeGen/X86/known-signbits-vector.ll
@@ -679,8 +679,6 @@
; X64: # %bb.0:
; X64-NEXT: vcmpeqsd %xmm1, %xmm0, %xmm0
; X64-NEXT: vmovq %xmm0, %rax
-; X64-NEXT: andl $1, %eax
-; X64-NEXT: negq %rax
; X64-NEXT: retq
%3 = fcmp oeq double %0, %1
%4 = sext i1 %3 to i64
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2792,16 +2792,26 @@
/// the opcode and bypass the mask operation.
static SDValue foldAddSubMasked1(bool IsAdd, SDValue N0, SDValue N1,
SelectionDAG &DAG, const SDLoc &DL) {
+ if (N1.getOpcode() == ISD::ZERO_EXTEND)
+ N1 = N1.getOperand(0);
+
if (N1.getOpcode() != ISD::AND || !isOneOrOneSplat(N1->getOperand(1)))
return SDValue();
EVT VT = N0.getValueType();
- if (DAG.ComputeNumSignBits(N1.getOperand(0)) != VT.getScalarSizeInBits())
+ SDValue N10 = N1.getOperand(0);
+ if (N10.getValueType() != VT && N10.getOpcode() == ISD::TRUNCATE)
+ N10 = N10.getOperand(0);
+
+ if (N10.getValueType() != VT)
+ return SDValue();
+
+ if (DAG.ComputeNumSignBits(N10) != VT.getScalarSizeInBits())
return SDValue();
// add N0, (and (AssertSext X, i1), 1) --> sub N0, X
// sub N0, (and (AssertSext X, i1), 1) --> add N0, X
- return DAG.getNode(IsAdd ? ISD::SUB : ISD::ADD, DL, VT, N0, N1.getOperand(0));
+ return DAG.getNode(IsAdd ? ISD::SUB : ISD::ADD, DL, VT, N0, N10);
}
/// Helper for doing combines based on N0 and N1 being added to each other.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141884.489668.patch
Type: text/x-patch
Size: 1822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230117/a9fee5d2/attachment.bin>
More information about the llvm-commits
mailing list