Skip to content

Commit 704fc65

Browse files
authored
[SelectionDAG] Prefer to use ATOMIC_LOAD extension type over getExtendForAtomicOps() in computeKnownBits/ComputeNumSignBits. (#136600)
If an ATOMIC_LOAD has ZEXTLOAD/SEXTLOAD extension type we should trust that over getExtendForAtomicOps(). SystemZ is the only target that uses setAtomicLoadExtAction and they return ANY_EXTEND from getExtendForAtomicOps(). So I'm not sure there's a way to get a contradiction currently. Note, type legalization uses getExtendForAtomicOps() when promoting ATOMIC_LOAD so we may not need to check getExtendForAtomicOps() for ATOMIC_LOAD. I have not done much investigating of this.
1 parent 863ead2 commit 704fc65

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,14 +4406,19 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
44064406
case ISD::ATOMIC_LOAD_UMIN:
44074407
case ISD::ATOMIC_LOAD_UMAX:
44084408
case ISD::ATOMIC_LOAD: {
4409-
unsigned MemBits =
4410-
cast<AtomicSDNode>(Op)->getMemoryVT().getScalarSizeInBits();
44114409
// If we are looking at the loaded value.
44124410
if (Op.getResNo() == 0) {
4413-
if (TLI->getExtendForAtomicOps() == ISD::ZERO_EXTEND)
4414-
Known.Zero.setBitsFrom(MemBits);
4415-
else if (Op->getOpcode() == ISD::ATOMIC_LOAD &&
4416-
cast<AtomicSDNode>(Op)->getExtensionType() == ISD::ZEXTLOAD)
4411+
auto *AT = cast<AtomicSDNode>(Op);
4412+
unsigned MemBits = AT->getMemoryVT().getScalarSizeInBits();
4413+
4414+
// For atomic_load, prefer to use the extension type.
4415+
if (Op->getOpcode() == ISD::ATOMIC_LOAD) {
4416+
if (AT->getExtensionType() == ISD::ZEXTLOAD)
4417+
Known.Zero.setBitsFrom(MemBits);
4418+
else if (AT->getExtensionType() != ISD::SEXTLOAD &&
4419+
TLI->getExtendForAtomicOps() == ISD::ZERO_EXTEND)
4420+
Known.Zero.setBitsFrom(MemBits);
4421+
} else if (TLI->getExtendForAtomicOps() == ISD::ZERO_EXTEND)
44174422
Known.Zero.setBitsFrom(MemBits);
44184423
}
44194424
break;
@@ -5252,22 +5257,29 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
52525257
case ISD::ATOMIC_LOAD_UMIN:
52535258
case ISD::ATOMIC_LOAD_UMAX:
52545259
case ISD::ATOMIC_LOAD: {
5255-
Tmp = cast<AtomicSDNode>(Op)->getMemoryVT().getScalarSizeInBits();
5260+
auto *AT = cast<AtomicSDNode>(Op);
52565261
// If we are looking at the loaded value.
52575262
if (Op.getResNo() == 0) {
5263+
Tmp = AT->getMemoryVT().getScalarSizeInBits();
52585264
if (Tmp == VTBits)
52595265
return 1; // early-out
5260-
if (TLI->getExtendForAtomicOps() == ISD::SIGN_EXTEND)
5261-
return VTBits - Tmp + 1;
5262-
if (TLI->getExtendForAtomicOps() == ISD::ZERO_EXTEND)
5263-
return VTBits - Tmp;
5266+
5267+
// For atomic_load, prefer to use the extension type.
52645268
if (Op->getOpcode() == ISD::ATOMIC_LOAD) {
5265-
ISD::LoadExtType ETy = cast<AtomicSDNode>(Op)->getExtensionType();
5266-
if (ETy == ISD::SEXTLOAD)
5269+
switch (AT->getExtensionType()) {
5270+
default:
5271+
break;
5272+
case ISD::SEXTLOAD:
52675273
return VTBits - Tmp + 1;
5268-
if (ETy == ISD::ZEXTLOAD)
5274+
case ISD::ZEXTLOAD:
52695275
return VTBits - Tmp;
5276+
}
52705277
}
5278+
5279+
if (TLI->getExtendForAtomicOps() == ISD::SIGN_EXTEND)
5280+
return VTBits - Tmp + 1;
5281+
if (TLI->getExtendForAtomicOps() == ISD::ZERO_EXTEND)
5282+
return VTBits - Tmp;
52715283
}
52725284
break;
52735285
}

0 commit comments

Comments
 (0)