Skip to content

Commit edbe6eb

Browse files
authored
SystemZ: Don't promote atomic store in IR (#90899)
This is the mirror to the recent atomic load change. The same bitcast-back-to-integer case is a small code quality regression for the same reason. This would disappear with a bitcastable legal 128-bit type.
1 parent 6535e7a commit edbe6eb

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,6 @@ SDValue DAGTypeLegalizer::SoftenFloatOp_STORE(SDNode *N, unsigned OpNo) {
11971197
}
11981198

11991199
SDValue DAGTypeLegalizer::SoftenFloatOp_ATOMIC_STORE(SDNode *N, unsigned OpNo) {
1200-
assert(ISD::isUNINDEXEDStore(N) && "Indexed store during type legalization!");
12011200
assert(OpNo == 1 && "Can only soften the stored value!");
12021201
AtomicSDNode *ST = cast<AtomicSDNode>(N);
12031202
SDValue Val = ST->getVal();

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
295295
setOperationAction(ISD::ATOMIC_LOAD, MVT::i128, Custom);
296296
setOperationAction(ISD::ATOMIC_STORE, MVT::i128, Custom);
297297
setOperationAction(ISD::ATOMIC_LOAD, MVT::f128, Custom);
298+
setOperationAction(ISD::ATOMIC_STORE, MVT::f128, Custom);
298299

299300
// Mark sign/zero extending atomic loads as legal, which will make
300301
// DAGCombiner fold extensions into atomic loads if possible.
@@ -941,9 +942,6 @@ SystemZTargetLowering::shouldCastAtomicLoadInIR(LoadInst *LI) const {
941942

942943
TargetLowering::AtomicExpansionKind
943944
SystemZTargetLowering::shouldCastAtomicStoreInIR(StoreInst *SI) const {
944-
// Lower fp128 the same way as i128.
945-
if (SI->getValueOperand()->getType()->isFP128Ty())
946-
return AtomicExpansionKind::CastToInteger;
947945
return AtomicExpansionKind::None;
948946
}
949947

@@ -6269,6 +6267,26 @@ static SDValue expandBitCastI128ToF128(SelectionDAG &DAG, SDValue Src,
62696267
return SDValue(Pair, 0);
62706268
}
62716269

6270+
static std::pair<SDValue, SDValue>
6271+
expandBitCastF128ToI128Parts(SelectionDAG &DAG, SDValue Src, const SDLoc &SL) {
6272+
SDValue LoFP =
6273+
DAG.getTargetExtractSubreg(SystemZ::subreg_l64, SL, MVT::f64, Src);
6274+
SDValue HiFP =
6275+
DAG.getTargetExtractSubreg(SystemZ::subreg_h64, SL, MVT::f64, Src);
6276+
SDValue Lo = DAG.getNode(ISD::BITCAST, SL, MVT::i64, LoFP);
6277+
SDValue Hi = DAG.getNode(ISD::BITCAST, SL, MVT::i64, HiFP);
6278+
6279+
return {Hi, Lo};
6280+
}
6281+
6282+
static SDValue expandBitCastF128ToI128(SelectionDAG &DAG, SDValue Src,
6283+
const SDLoc &SL) {
6284+
6285+
auto [Hi, Lo] = expandBitCastF128ToI128Parts(DAG, Src, SL);
6286+
SDNode *Pair = DAG.getMachineNode(SystemZ::PAIR128, SL, MVT::Untyped, Hi, Lo);
6287+
return SDValue(Pair, 0);
6288+
}
6289+
62726290
// Lower operations with invalid operand or result types (currently used
62736291
// only for 128-bit integer types).
62746292
void
@@ -6307,8 +6325,17 @@ SystemZTargetLowering::LowerOperationWrapper(SDNode *N,
63076325
case ISD::ATOMIC_STORE: {
63086326
SDLoc DL(N);
63096327
SDVTList Tys = DAG.getVTList(MVT::Other);
6310-
SDValue Ops[] = {N->getOperand(0), lowerI128ToGR128(DAG, N->getOperand(1)),
6311-
N->getOperand(2)};
6328+
SDValue Val = N->getOperand(1);
6329+
EVT VT = Val.getValueType();
6330+
6331+
if (VT == MVT::i128 || isTypeLegal(MVT::i128)) {
6332+
Val = DAG.getBitcast(MVT::i128, Val);
6333+
Val = lowerI128ToGR128(DAG, Val);
6334+
} else {
6335+
Val = expandBitCastF128ToI128(DAG, Val, DL);
6336+
}
6337+
6338+
SDValue Ops[] = {N->getOperand(0), Val, N->getOperand(2)};
63126339
MachineMemOperand *MMO = cast<AtomicSDNode>(N)->getMemOperand();
63136340
SDValue Res = DAG.getMemIntrinsicNode(SystemZISD::ATOMIC_STORE_128,
63146341
DL, Tys, Ops, MVT::i128, MMO);
@@ -6351,15 +6378,12 @@ SystemZTargetLowering::LowerOperationWrapper(SDNode *N,
63516378
Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i64, VecBC,
63526379
DAG.getConstant(0, DL, MVT::i32));
63536380
} else {
6381+
// FIXME: Assert should be moved into expandBitCastF128ToI128Parts
63546382
assert(getRepRegClassFor(MVT::f128) == &SystemZ::FP128BitRegClass &&
63556383
"Unrecognized register class for f128.");
6356-
SDValue LoFP = DAG.getTargetExtractSubreg(SystemZ::subreg_l64,
6357-
DL, MVT::f64, Src);
6358-
SDValue HiFP = DAG.getTargetExtractSubreg(SystemZ::subreg_h64,
6359-
DL, MVT::f64, Src);
6360-
Lo = DAG.getNode(ISD::BITCAST, DL, MVT::i64, LoFP);
6361-
Hi = DAG.getNode(ISD::BITCAST, DL, MVT::i64, HiFP);
6384+
std::tie(Hi, Lo) = expandBitCastF128ToI128Parts(DAG, Src, DL);
63626385
}
6386+
63636387
Results.push_back(DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i128, Lo, Hi));
63646388
}
63656389
break;

llvm/test/CodeGen/SystemZ/atomic-store-08.ll

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
; Test long double atomic stores. The atomic store is converted to i128 by
2-
; the AtomicExpand pass.
1+
; Test long double atomic stores. The atomic store is converted to i128
32
;
43
; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck -check-prefixes=CHECK,BASE %s
54
; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z13 | FileCheck -check-prefixes=CHECK,Z13 %s
@@ -8,14 +7,24 @@
87
; RUN: llc < %s -mtriple=s390x-linux-gnu -mattr=+soft-float | FileCheck -check-prefixes=SOFTFP %s
98

109

10+
; FIXME: With legal 128-bit operation to bitcast, the base code would
11+
; be the same as z13
1112
define void @f1(ptr %dst, ptr %src) {
1213
; CHECK-LABEL: f1:
1314
; CHECK: # %bb.0:
14-
; CHECK-NEXT: lg %r1, 8(%r3)
15-
; CHECK-NEXT: lg %r0, 0(%r3)
16-
; CHECK-NEXT: stpq %r0, 0(%r2)
17-
; CHECK-NEXT: bcr 1{{[45]}}, %r0
18-
; CHECK-NEXT: br %r14
15+
; Z13-NEXT: lg %r1, 8(%r3)
16+
; Z13-NEXT: lg %r0, 0(%r3)
17+
; Z13-NEXT: stpq %r0, 0(%r2)
18+
; Z13-NEXT: bcr 1{{[45]}}, %r0
19+
; Z13-NEXT: br %r14
20+
21+
; BASE-NEXT: ld %f0, 0(%r3)
22+
; BASE-NEXT: ld %f2, 8(%r3)
23+
; BASE-NEXT: lgdr %r1, %f2
24+
; BASE-NEXT: lgdr %r0, %f0
25+
; BASE-NEXT: stpq %r0, 0(%r2)
26+
; BASE-NEXT: bcr 15, %r0
27+
; BASE-NEXT: br %r14
1928

2029
; SOFTFP-LABEL: f1:
2130
; SOFTFP: # %bb.0:

0 commit comments

Comments
 (0)