Skip to content

Commit cc73448

Browse files
committed
DAG: Simplify demanded bits for truncating atomic_store
It's really unfortunate that STORE and ATOMIC_STORE are separate opcodes. This duplicates a basic simplify demanded for the truncating case. This avoids some AMDGPU lit regressions in a future patch. I'm not sure how to craft a test that exposes this without first introducing the regressions by promoting half to i16.
1 parent f1112eb commit cc73448

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ namespace {
530530
bool refineExtractVectorEltIntoMultipleNarrowExtractVectorElts(SDNode *N);
531531

532532
SDValue visitSTORE(SDNode *N);
533+
SDValue visitATOMIC_STORE(SDNode *N);
533534
SDValue visitLIFETIME_END(SDNode *N);
534535
SDValue visitINSERT_VECTOR_ELT(SDNode *N);
535536
SDValue visitEXTRACT_VECTOR_ELT(SDNode *N);
@@ -1909,6 +1910,7 @@ SDValue DAGCombiner::visit(SDNode *N) {
19091910
case ISD::BR_CC: return visitBR_CC(N);
19101911
case ISD::LOAD: return visitLOAD(N);
19111912
case ISD::STORE: return visitSTORE(N);
1913+
case ISD::ATOMIC_STORE: return visitATOMIC_STORE(N);
19121914
case ISD::INSERT_VECTOR_ELT: return visitINSERT_VECTOR_ELT(N);
19131915
case ISD::EXTRACT_VECTOR_ELT: return visitEXTRACT_VECTOR_ELT(N);
19141916
case ISD::BUILD_VECTOR: return visitBUILD_VECTOR(N);
@@ -21096,6 +21098,24 @@ SDValue DAGCombiner::replaceStoreOfInsertLoad(StoreSDNode *ST) {
2109621098
ST->getMemOperand()->getFlags());
2109721099
}
2109821100

21101+
SDValue DAGCombiner::visitATOMIC_STORE(SDNode *N) {
21102+
AtomicSDNode *ST = cast<AtomicSDNode>(N);
21103+
SDValue Val = ST->getVal();
21104+
EVT VT = Val.getValueType();
21105+
EVT MemVT = ST->getMemoryVT();
21106+
21107+
if (MemVT.bitsLT(VT)) { // Is truncating store
21108+
APInt TruncDemandedBits = APInt::getLowBitsSet(VT.getScalarSizeInBits(),
21109+
MemVT.getScalarSizeInBits());
21110+
// See if we can simplify the operation with SimplifyDemandedBits, which
21111+
// only works if the value has a single use.
21112+
if (SimplifyDemandedBits(Val, TruncDemandedBits))
21113+
return SDValue(N, 0);
21114+
}
21115+
21116+
return SDValue();
21117+
}
21118+
2109921119
SDValue DAGCombiner::visitSTORE(SDNode *N) {
2110021120
StoreSDNode *ST = cast<StoreSDNode>(N);
2110121121
SDValue Chain = ST->getChain();

0 commit comments

Comments
 (0)