Skip to content

Commit 305fbe6

Browse files
committed
Remove fp<->int bitcasting in SystemZ backend.
1 parent 05be915 commit 305fbe6

File tree

6 files changed

+9
-112
lines changed

6 files changed

+9
-112
lines changed

llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,21 +1761,12 @@ void SystemZDAGToDAGISel::Select(SDNode *Node) {
17611761

17621762
case ISD::ATOMIC_STORE: {
17631763
auto *AtomOp = cast<AtomicSDNode>(Node);
1764-
// Store FP values directly without first moving to a GPR. This is needed
1765-
// as long as clang always emits the cast to integer.
1766-
EVT SVT = AtomOp->getMemoryVT();
1767-
SDValue StoredVal = AtomOp->getVal();
1768-
if (SVT.isInteger() && StoredVal->getOpcode() == ISD::BITCAST &&
1769-
StoredVal->getOperand(0).getValueType().isFloatingPoint()) {
1770-
StoredVal = StoredVal->getOperand(0);
1771-
SVT = StoredVal.getValueType();
1772-
}
17731764
// Replace the atomic_store with a regular store and select it. This is
17741765
// ok since we know all store instructions <= 8 bytes are atomic, and the
17751766
// 16 byte case is already handled during lowering.
17761767
StoreSDNode *St = cast<StoreSDNode>(CurDAG->getTruncStore(
1777-
AtomOp->getChain(), SDLoc(AtomOp), StoredVal, AtomOp->getBasePtr(), SVT,
1778-
AtomOp->getMemOperand()));
1768+
AtomOp->getChain(), SDLoc(AtomOp), AtomOp->getVal(),
1769+
AtomOp->getBasePtr(), AtomOp->getMemoryVT(), AtomOp->getMemOperand()));
17791770
assert(St->getMemOperand()->isAtomic() && "Broken MMO.");
17801771
SDNode *Chain = St;
17811772
// We have to enforce sequential consistency by performing a

llvm/lib/Target/SystemZ/SystemZISelLowering.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,7 @@ SystemZTargetLowering::SystemZTargetLowering(const TargetMachine &TM,
695695
setOperationAction(ISD::GET_ROUNDING, MVT::i32, Custom);
696696

697697
// Codes for which we want to perform some z-specific combinations.
698-
setTargetDAGCombine({ISD::BITCAST,
699-
ISD::ZERO_EXTEND,
698+
setTargetDAGCombine({ISD::ZERO_EXTEND,
700699
ISD::SIGN_EXTEND,
701700
ISD::SIGN_EXTEND_INREG,
702701
ISD::LOAD,
@@ -916,7 +915,6 @@ bool SystemZTargetLowering::hasInlineStackProbe(const MachineFunction &MF) const
916915
return false;
917916
}
918917

919-
// FIXME: Clang emits these casts always regardless of these hooks.
920918
TargetLowering::AtomicExpansionKind
921919
SystemZTargetLowering::shouldCastAtomicLoadInIR(LoadInst *LI) const {
922920
// Lower fp128 the same way as i128.
@@ -6597,32 +6595,6 @@ static SDValue extendAtomicLoad(AtomicSDNode *ALoad, EVT VT, SelectionDAG &DAG,
65976595
return SDValue(NewALoad, 0);
65986596
}
65996597

6600-
SDValue SystemZTargetLowering::combineBITCAST(SDNode *N,
6601-
DAGCombinerInfo &DCI) const {
6602-
SelectionDAG &DAG = DCI.DAG;
6603-
SDValue N0 = N->getOperand(0);
6604-
EVT InVT = N0.getValueType();
6605-
EVT ResVT = N->getValueType(0);
6606-
// Handle atomic loads to load float/double values directly and not via a
6607-
// GPR. Do it before legalization to help in treating the ATOMIC_LOAD the
6608-
// same way as a LOAD, and e.g. emit a REPLICATE. FIXME: This is only
6609-
// needed because clang currently emits these casts always.
6610-
if (auto *ALoad = dyn_cast<AtomicSDNode>(N0))
6611-
if (ALoad->getOpcode() == ISD::ATOMIC_LOAD && InVT.getSizeInBits() <= 64 &&
6612-
ALoad->getExtensionType() == ISD::NON_EXTLOAD &&
6613-
SDValue(ALoad, 0).hasOneUse() && InVT.isInteger() &&
6614-
ResVT.isFloatingPoint()) {
6615-
SDValue Res = DAG.getAtomic(ISD::ATOMIC_LOAD, SDLoc(N), ResVT, ResVT,
6616-
ALoad->getChain(), ALoad->getBasePtr(),
6617-
ALoad->getMemOperand());
6618-
// Update the chain uses.
6619-
DAG.ReplaceAllUsesOfValueWith(SDValue(ALoad, 1), Res.getValue(1));
6620-
return Res;
6621-
}
6622-
6623-
return SDValue();
6624-
}
6625-
66266598
SDValue SystemZTargetLowering::combineZERO_EXTEND(
66276599
SDNode *N, DAGCombinerInfo &DCI) const {
66286600
// Convert (zext (select_ccmask C1, C2)) into (select_ccmask C1', C2')
@@ -7683,7 +7655,6 @@ SDValue SystemZTargetLowering::PerformDAGCombine(SDNode *N,
76837655
DAGCombinerInfo &DCI) const {
76847656
switch(N->getOpcode()) {
76857657
default: break;
7686-
case ISD::BITCAST: return combineBITCAST(N, DCI);
76877658
case ISD::ZERO_EXTEND: return combineZERO_EXTEND(N, DCI);
76887659
case ISD::SIGN_EXTEND: return combineSIGN_EXTEND(N, DCI);
76897660
case ISD::SIGN_EXTEND_INREG: return combineSIGN_EXTEND_INREG(N, DCI);

llvm/lib/Target/SystemZ/SystemZISelLowering.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ class SystemZTargetLowering : public TargetLowering {
724724
bool Force) const;
725725
SDValue combineTruncateExtract(const SDLoc &DL, EVT TruncVT, SDValue Op,
726726
DAGCombinerInfo &DCI) const;
727-
SDValue combineBITCAST(SDNode *N, DAGCombinerInfo &DCI) const;
728727
SDValue combineZERO_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
729728
SDValue combineSIGN_EXTEND(SDNode *N, DAGCombinerInfo &DCI) const;
730729
SDValue combineSIGN_EXTEND_INREG(SDNode *N, DAGCombinerInfo &DCI) const;

llvm/lib/Target/SystemZ/SystemZOperators.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def zext32 : PatFrag<(ops node:$src), (zext (i32 node:$src))>;
538538
def z_load : PatFrags<(ops node:$ptr),
539539
[(load node:$ptr),
540540
(atomic_load node:$ptr)], [{
541-
if (auto *AL = dyn_cast<AtomicSDNode>(N)) // XXXX getLoadExtType?
541+
if (auto *AL = dyn_cast<AtomicSDNode>(N))
542542
if (AL->getExtensionType() != ISD::NON_EXTLOAD)
543543
return false;
544544
return true;
@@ -680,7 +680,7 @@ def z_any_extloadf64 : PatFrags<(ops node:$ptr),
680680
class AlignedLoad<SDPatternOperator load>
681681
: PatFrag<(ops node:$addr), (load node:$addr),
682682
[{ return storeLoadIsAligned(N); }]>;
683-
def aligned_z_load : AlignedLoad<z_load>;
683+
def aligned_z_load : AlignedLoad<z_load>;
684684
def aligned_z_asextloadi16 : AlignedLoad<z_asextloadi16>;
685685
def aligned_z_asextloadi32 : AlignedLoad<z_asextloadi32>;
686686
def aligned_z_azextloadi16 : AlignedLoad<z_azextloadi16>;

llvm/lib/Target/VE/VEInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ defm : TRUNC64m<truncstorei8, ST1Brri, ST1Brii, ST1Bzri, ST1Bzii>;
17851785
defm : TRUNC64m<truncstorei16, ST2Brri, ST2Brii, ST2Bzri, ST2Bzii>;
17861786
defm : TRUNC64m<truncstorei32, STLrri, STLrii, STLzri, ST1Bzii>;
17871787

1788-
// Atomic loads
1788+
// Atomic loads (FIXME: replace iAny with the correct integer VT:)
17891789
multiclass ATMLDm<SDPatternOperator from,
17901790
RM torri, RM torii,
17911791
RM tozri, RM tozii> {

llvm/test/CodeGen/SystemZ/atomic-memops.ll

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,6 @@ define void @f25(ptr %src, ptr %dst) {
408408
ret void
409409
}
410410

411-
define void @f25_b(ptr %src, ptr %dst) {
412-
; CHECK-LABEL: f25_b:
413-
; CHECK: # %bb.0:
414-
; CHECK-NEXT: vlrepf %v0, 0(%r2)
415-
; CHECK-NEXT: vst %v0, 0(%r3), 3
416-
; CHECK-NEXT: br %r14
417-
%l = load atomic i32, ptr %src seq_cst, align 4
418-
%b = bitcast i32 %l to float
419-
%v = insertelement <4 x float> undef, float %b, i32 1
420-
store volatile <4 x float> %v, ptr %dst
421-
ret void
422-
}
423-
424411
; Do *not* use vlrep for an extending load.
425412
define <4 x i32> @f25_c(ptr %ptr) {
426413
; CHECK-LABEL: f25_c:
@@ -466,21 +453,6 @@ define void @f26(ptr %src, ptr %dst) {
466453
ret void
467454
}
468455

469-
define void @f26_b(ptr %src, ptr %dst) {
470-
; CHECK-LABEL: f26_b:
471-
; CHECK: # %bb.0:
472-
; CHECK-NEXT: vlrepg %v0, 0(%r2)
473-
; CHECK-NEXT: vst %v0, 0(%r3), 3
474-
; CHECK-NEXT: br %r14
475-
%l = load atomic i64, ptr %src seq_cst, align 8
476-
%b = bitcast i64 %l to double
477-
%v = insertelement <2 x double> undef, double %b, i32 0
478-
store volatile <2 x double> %v, ptr %dst
479-
ret void
480-
}
481-
482-
483-
484456
; Vector Load logical element and zero.
485457
define <16 x i8> @f27(ptr %ptr) {
486458
; CHECK-LABEL: f27:
@@ -583,40 +555,6 @@ define <2 x i64> @f36(<2 x i64> %val, ptr %ptr) {
583555
ret <2 x i64> %ret
584556
}
585557

586-
; Test that fp values are loaded/stored directly. Clang FE currently always
587-
; emits atomic load/stores casted this way.
588-
define void @f37(ptr %src, ptr %dst) {
589-
; CHECK-LABEL: f37:
590-
; CHECK: # %bb.0:
591-
; CHECK-NEXT: ld %f0, 0(%r2)
592-
; CHECK-NEXT: adbr %f0, %f0
593-
; CHECK-NEXT: std %f0, 0(%r3)
594-
; CHECK-NEXT: bcr 14, %r0
595-
; CHECK-NEXT: br %r14
596-
%atomic-load = load atomic i64, ptr %src seq_cst, align 8
597-
%bc0 = bitcast i64 %atomic-load to double
598-
%fa = fadd double %bc0, %bc0
599-
%bc1 = bitcast double %fa to i64
600-
store atomic i64 %bc1, ptr %dst seq_cst, align 8
601-
ret void
602-
}
603-
604-
define void @f38(ptr %src, ptr %dst) {
605-
; CHECK-LABEL: f38:
606-
; CHECK: # %bb.0:
607-
; CHECK-NEXT: lde %f0, 0(%r2)
608-
; CHECK-NEXT: aebr %f0, %f0
609-
; CHECK-NEXT: ste %f0, 0(%r3)
610-
; CHECK-NEXT: bcr 14, %r0
611-
; CHECK-NEXT: br %r14
612-
%atomic-load = load atomic i32, ptr %src seq_cst, align 8
613-
%bc0 = bitcast i32 %atomic-load to float
614-
%fa = fadd float %bc0, %bc0
615-
%bc1 = bitcast float %fa to i32
616-
store atomic i32 %bc1, ptr %dst seq_cst, align 8
617-
ret void
618-
}
619-
620558
; Test operation on memory involving atomic load and store.
621559
define void @f39(ptr %ptr) {
622560
; CHECK-LABEL: f39:
@@ -676,7 +614,7 @@ define void @f43(ptr %ptr) {
676614
define void @f44(ptr %ptr) {
677615
; CHECK-LABEL: f44:
678616
; CHECK: # %bb.0:
679-
; CHECK-NEXT: larl %r1, .LCPI53_0
617+
; CHECK-NEXT: larl %r1, .LCPI49_0
680618
; CHECK-NEXT: ld %f0, 0(%r1)
681619
; CHECK-NEXT: std %f0, 0(%r2)
682620
; CHECK-NEXT: bcr 14, %r0
@@ -767,8 +705,7 @@ define void @f51(ptr %src, ptr %dst) {
767705
%b0 = bitcast i128 %atomic-load to <4 x float>
768706
%vecext = extractelement <4 x float> %b0, i64 0
769707
%add = fadd float %vecext, 1.000000e+00
770-
%b1 = bitcast float %add to i32
771-
store atomic i32 %b1, ptr %dst seq_cst, align 4
708+
store atomic float %add, ptr %dst seq_cst, align 4
772709
ret void
773710
}
774711

@@ -786,8 +723,7 @@ define void @f52(ptr %src, ptr %dst) {
786723
%b0 = bitcast i128 %atomic-load to <2 x double>
787724
%vecext = extractelement <2 x double> %b0, i64 0
788725
%add = fadd double %vecext, 1.000000e+00
789-
%b1 = bitcast double %add to i64
790-
store atomic i64 %b1, ptr %dst seq_cst, align 8
726+
store atomic double %add, ptr %dst seq_cst, align 8
791727
ret void
792728
}
793729

0 commit comments

Comments
 (0)