Index: llvm/lib/Target/SystemZ/SystemZInstrFormats.td =================================================================== --- llvm/lib/Target/SystemZ/SystemZInstrFormats.td +++ llvm/lib/Target/SystemZ/SystemZInstrFormats.td @@ -3135,7 +3135,8 @@ mnemonic#"\t$R1, $R2, $R3", [(set cls1:$R1, (operator cls2:$R2, cls3:$R3))]> { let M4 = 0; - let OpKey = mnemonic#cls1; + // Change MSRKC and MSGRKC names during tablegen mapping to work with "rk". + let OpKey = !subst("msgrkc", "msgcrk", !subst("msrkc", "mscrk", mnemonic))#cls1; let OpType = "reg"; } Index: llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp =================================================================== --- llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp +++ llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp @@ -1078,6 +1078,32 @@ return BuiltMI; } + unsigned MemImmOpc = 0; + switch (Opcode) { + case SystemZ::LHIMux: + case SystemZ::LHI: MemImmOpc = SystemZ::MVHI; break; + case SystemZ::LGHI: MemImmOpc = SystemZ::MVGHI; break; + case SystemZ::CHIMux: + case SystemZ::CHI: MemImmOpc = SystemZ::CHSI; break; + case SystemZ::CGHI: MemImmOpc = SystemZ::CGHSI; break; + case SystemZ::CLFIMux: + case SystemZ::CLFI: + if (isUInt<16>(MI.getOperand(1).getImm())) + MemImmOpc = SystemZ::CLFHSI; + break; + case SystemZ::CLGFI: + if (isUInt<16>(MI.getOperand(1).getImm())) + MemImmOpc = SystemZ::CLGHSI; + break; + default: break; + } + if (MemImmOpc) + return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), + get(MemImmOpc)) + .addFrameIndex(FrameIndex) + .addImm(0) + .addImm(MI.getOperand(1).getImm()); + if (Opcode == SystemZ::LGDR || Opcode == SystemZ::LDGR) { bool Op0IsGPR = (Opcode == SystemZ::LGDR); bool Op1IsGPR = (Opcode == SystemZ::LDGR); @@ -1105,6 +1131,32 @@ } } + if (Opcode == SystemZ::LEFR) { + Register DstReg = MI.getOperand(0).getReg(); + const MachineRegisterInfo &MRI = MF.getRegInfo(); + if (Register::isVirtualRegister(DstReg) && + MRI.getRegClass(DstReg) == &SystemZ::FP32BitRegClass) { + // If we are spilling the destination of an LEFR, store the source + // register instead. + if (OpNum == 0) + return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), + get(SystemZ::ST)) + .add(MI.getOperand(1)) + .addFrameIndex(FrameIndex) + .addImm(0) + .addReg(0); + // If we're spilling the source of an LEFR, load the destination + // register instead. + if (OpNum == 1) + return BuildMI(*InsertPt->getParent(), InsertPt, MI.getDebugLoc(), + get(SystemZ::LE)) + .add(MI.getOperand(0)) + .addFrameIndex(FrameIndex) + .addImm(0) + .addReg(0); + } + } + // Look for cases where the source of a simple store or the destination // of a simple load is being spilled. Try to use MVC instead. // @@ -1172,7 +1224,8 @@ // See if this is a 3-address instruction that is convertible to 2-address // and suitable for folding below. Only try this with virtual registers // and a provided VRM (during regalloc). - if (SystemZ::getTwoOperandOpcode(Opcode) != -1) { + if (SystemZ::getTwoOperandOpcode(Opcode) != -1 || + Opcode == SystemZ::MSRKC || Opcode == SystemZ::MSGRKC) { if (VRM == nullptr) return nullptr; else { Index: llvm/lib/Target/SystemZ/SystemZInstrInfo.td =================================================================== --- llvm/lib/Target/SystemZ/SystemZInstrInfo.td +++ llvm/lib/Target/SystemZ/SystemZInstrInfo.td @@ -1348,8 +1348,8 @@ // Multiplication of memory, setting the condition code. let Predicates = [FeatureMiscellaneousExtensions2], Defs = [CC] in { - def MSC : BinaryRXY<"msc", 0xE353, null_frag, GR32, load, 4>; - def MSGC : BinaryRXY<"msgc", 0xE383, null_frag, GR64, load, 8>; + defm MSC : BinaryRXYAndPseudo<"msc", 0xE353, null_frag, GR32, load, 4>; + defm MSGC : BinaryRXYAndPseudo<"msgc", 0xE383, null_frag, GR64, load, 8>; } // Multiplication of a register, producing two results. Index: llvm/test/CodeGen/SystemZ/foldmemop-imm-01.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/SystemZ/foldmemop-imm-01.ll @@ -0,0 +1,55 @@ +; RUN: llc < %s -mtriple=s390x-linux-gnu -O3 -mcpu=z10 | FileCheck %s +; RUN: llc < %s -mtriple=s390x-linux-gnu -O3 -mcpu=z14 | FileCheck %s +; +; Test folding of spilled immediate loads and compares. + +define i32 @fun0(i32 *%src, i32 %arg) nounwind { +; CHECK-LABEL: fun0: +; CHECK: mvhi 164(%r15), 0 # 4-byte Folded Spill +; CHECK: mvc 164(4,%r15), 0(%r2) # 4-byte Folded Spill +; CHECK-LABEL: .LBB0_2: +; CHECK: chsi 164(%r15), 2 # 4-byte Folded Reload + +entry: + %cmp = icmp eq i32 %arg, 0 + br i1 %cmp, label %cond, label %exit + +cond: + %val0 = load i32, i32 *%src + call void asm sideeffect "", "~{r0},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15}"() nounwind + br label %exit + +exit: + %tmp0 = phi i32 [0, %entry], [%val0, %cond] + call void asm sideeffect "", "~{r0},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15}"() nounwind + %cmp0 = icmp ne i32 %tmp0, 2 + %zxt0 = zext i1 %cmp0 to i32 + %and0 = and i32 %arg, %zxt0 + + ret i32 %and0 +} + +define i64 @fun1(i64 *%src, i64 %arg) nounwind { +; CHECK-LABEL: fun1: +; CHECK: mvghi 168(%r15), 0 # 8-byte Folded Spill +; CHECK: mvc 168(8,%r15), 0(%r2) # 8-byte Folded Spill +; CHECK-LABEL: .LBB1_2: +; CHECK: cghsi 168(%r15), 2 # 8-byte Folded Reload +entry: + %cmp = icmp eq i64 %arg, 0 + br i1 %cmp, label %cond, label %exit + +cond: + %val0 = load i64, i64 *%src + call void asm sideeffect "", "~{r0},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15}"() nounwind + br label %exit + +exit: + %tmp0 = phi i64 [0, %entry], [%val0, %cond] + call void asm sideeffect "", "~{r0},~{r1},~{r2},~{r3},~{r4},~{r5},~{r6},~{r7},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15}"() nounwind + %cmp0 = icmp ne i64 %tmp0, 2 + %zxt0 = zext i1 %cmp0 to i64 + %and0 = and i64 %arg, %zxt0 + + ret i64 %and0 +} Index: llvm/test/CodeGen/SystemZ/foldmemop-imm-02.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/SystemZ/foldmemop-imm-02.mir @@ -0,0 +1,233 @@ +# RUN: llc -mtriple=s390x-linux-gnu -mcpu=z14 -start-before=greedy %s -o - \ +# RUN: | FileCheck %s +# +# Test folding of a memory operand into logical compare with an immediate. + +--- | + define i32 @fun0(i32* %src, i32 %arg) { ret i32 0 } + define i64 @fun1(i64* %src, i64 %arg) { ret i64 0 } + define i32 @fun2(i32* %src, i32 %arg) { ret i32 0 } + define i64 @fun3(i64* %src, i64 %arg) { ret i64 0 } +... + + +# CHECK-LABEL: fun0: +# CHECK: mvhi 164(%r15), 0 # 4-byte Folded Spill +# CHECK: mvc 164(4,%r15), 0(%r2) # 4-byte Folded Spill +# CHECK-LABEL: .LBB0_2: +# CHECK: clfhsi 164(%r15), 2 # 4-byte Folded Reload +--- +name: fun0 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: grx32bit } + - { id: 1, class: grx32bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr32bit } + - { id: 4, class: grx32bit } + - { id: 5, class: grx32bit } + - { id: 6, class: gr32bit } + - { id: 7, class: gr32bit } + - { id: 8, class: grx32bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3l', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3l + + %3:gr32bit = COPY $r3l + %2:addr64bit = COPY $r2d + %6:gr32bit = LHIMux 0 + CHIMux %3, 0, implicit-def $cc + %8:grx32bit = LHIMux 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:grx32bit = LMux %2, 0, $noreg :: (load 4 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + CLFIMux %8, 2, implicit-def $cc + %6:gr32bit = LOCHIMux %6, 1, 14, 6, implicit killed $cc + %7:gr32bit = NRK %3, %6, implicit-def dead $cc + $r2l = COPY %7 + Return implicit $r2l + +... + + +# CHECK-LABEL: fun1: +# CHECK: mvghi 168(%r15), 0 # 8-byte Folded Spill +# CHECK: mvc 168(8,%r15), 0(%r2) # 8-byte Folded Spill +# CHECK-LABEL: .LBB1_2: +# CHECK: clghsi 168(%r15), 2 # 8-byte Folded Reload +--- +name: fun1 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: gr64bit } + - { id: 1, class: gr64bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr64bit } + - { id: 4, class: gr64bit } + - { id: 5, class: gr64bit } + - { id: 6, class: gr64bit } + - { id: 7, class: gr64bit } + - { id: 8, class: gr64bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3d', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3d + + %3:gr64bit = COPY $r3d + %2:addr64bit = COPY $r2d + %6:gr64bit = LGHI 0 + CGHI %3, 0, implicit-def $cc + %8:gr64bit = LGHI 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:gr64bit = LG %2, 0, $noreg :: (load 8 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + CLGFI %8, 2, implicit-def $cc + %6:gr64bit = LOCGHI %6, 1, 14, 6, implicit killed $cc + %7:gr64bit = NGRK %3, %6, implicit-def dead $cc + $r2d = COPY %7 + Return implicit $r2d + +... + + +# 17-bit immediate can not be folded + +# CHECK-LABEL: fun2: +# CHECK: mvhi 164(%r15), 0 # 4-byte Folded Spill +# CHECK: mvc 164(4,%r15), 0(%r2) # 4-byte Folded Spill +# CHECK-LABEL: .LBB2_2: +# CHECK: l %r0, 164(%r15) # 4-byte Folded Reload +# CHECK: clfi %r0, 65536 +--- +name: fun2 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: grx32bit } + - { id: 1, class: grx32bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr32bit } + - { id: 4, class: grx32bit } + - { id: 5, class: grx32bit } + - { id: 6, class: gr32bit } + - { id: 7, class: gr32bit } + - { id: 8, class: grx32bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3l', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3l + + %3:gr32bit = COPY $r3l + %2:addr64bit = COPY $r2d + %6:gr32bit = LHIMux 0 + CHIMux %3, 0, implicit-def $cc + %8:grx32bit = LHIMux 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:grx32bit = LMux %2, 0, $noreg :: (load 4 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + CLFIMux %8, 65536, implicit-def $cc + %6:gr32bit = LOCHIMux %6, 1, 14, 6, implicit killed $cc + %7:gr32bit = NRK %3, %6, implicit-def dead $cc + $r2l = COPY %7 + Return implicit $r2l + +... + + +# 17-bit immediate can not be folded + +# CHECK-LABEL: fun3: +# CHECK: mvghi 168(%r15), 0 # 8-byte Folded Spill +# CHECK: mvc 168(8,%r15), 0(%r2) # 8-byte Folded Spill +# CHECK-LABEL: .LBB3_2: +# CHECK: lg %r0, 168(%r15) # 8-byte Folded Reload +# CHECK: clgfi %r0, 65536 +--- +name: fun3 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: gr64bit } + - { id: 1, class: gr64bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr64bit } + - { id: 4, class: gr64bit } + - { id: 5, class: gr64bit } + - { id: 6, class: gr64bit } + - { id: 7, class: gr64bit } + - { id: 8, class: gr64bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3d', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3d + + %3:gr64bit = COPY $r3d + %2:addr64bit = COPY $r2d + %6:gr64bit = LGHI 0 + CGHI %3, 0, implicit-def $cc + %8:gr64bit = LGHI 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:gr64bit = LG %2, 0, $noreg :: (load 8 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + CLGFI %8, 65536, implicit-def $cc + %6:gr64bit = LOCGHI %6, 1, 14, 6, implicit killed $cc + %7:gr64bit = NGRK %3, %6, implicit-def dead $cc + $r2d = COPY %7 + Return implicit $r2d + +... Index: llvm/test/CodeGen/SystemZ/foldmemop-lefr.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/SystemZ/foldmemop-lefr.mir @@ -0,0 +1,93 @@ +# RUN: llc -mtriple=s390x-linux-gnu -mcpu=z14 -start-before=greedy %s -o - \ +# RUN: | FileCheck %s +# +# Test folding of a memory operand into a lefr source or destionation register. + + +--- | + declare float @bar(float) #0 + define void @fun0() #0 { unreachable } + define void @fun1() #0 { unreachable } + attributes #0 = { nounwind } +... + +# CHECK-LABEL: fun0: +# CHECK-LABEL: .LBB0_2: +# CHECK: lde %f0, 164(%r15) # 4-byte Folded Reload +--- +name: 'fun0' +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: gr32bit } + - { id: 1, class: vr32bit } + - { id: 2, class: vr32bit } + - { id: 3, class: addr64bit } + - { id: 4, class: vr32bit } + - { id: 5, class: vr32bit } + - { id: 6, class: vr32bit } + - { id: 7, class: fp32bit } + - { id: 8, class: fp32bit } + - { id: 9, class: addr64bit } + - { id: 10, class: addr64bit } +frameInfo: + maxAlignment: 1 + hasCalls: true +machineFunctionInfo: {} +body: | + bb.0: + %1:vr32bit = nofpexcept WFSQSB undef %4:vr32bit, implicit $fpc + %0:gr32bit = LMux undef %3:addr64bit, 0, $noreg :: (load 4 from `i32* undef`) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def dead early-clobber $f0d, 12, implicit-def dead early-clobber $f1d, 12, implicit-def dead early-clobber $f2d, 12, implicit-def dead early-clobber $f3d, 12, implicit-def dead early-clobber $f4d, 12, implicit-def dead early-clobber $f5d, 12, implicit-def dead early-clobber $f6d, 12, implicit-def dead early-clobber $f7d, 12, implicit-def dead early-clobber $f8d, 12, implicit-def dead early-clobber $f9d, 12, implicit-def dead early-clobber $f10d, 12, implicit-def dead early-clobber $f11d, 12, implicit-def dead early-clobber $f12d, 12, implicit-def dead early-clobber $f13d, 12, implicit-def dead early-clobber $f14d, 12, implicit-def dead early-clobber $f14d, 12, implicit-def dead early-clobber $f15d + nofpexcept WFCSB %1, %1, implicit-def $cc, implicit $fpc + BRC 15, 14, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + ADJCALLSTACKDOWN 0, 0 + CallBRASL @bar, undef $f0s, csr_systemz, implicit-def dead $r14d, implicit-def dead $cc, implicit $fpc, implicit-def dead $f0s + ADJCALLSTACKUP 0, 0 + + bb.2: + %8:fp32bit = LEFR %0 + %8:fp32bit = contract nofpexcept SEB %8, undef %9:addr64bit, 0, $noreg, implicit-def dead $cc, implicit $fpc :: (load 4 from `float* undef`) + VST32 %8, undef %10:addr64bit, 0, $noreg :: (store 4 into `float* undef`) + +... + + +# CHECK-LABEL: fun1: +# CHECK: st %r0, 164(%r15) # 4-byte Folded Spill +--- +name: fun1 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: gr64bit } + - { id: 1, class: addr64bit } + - { id: 2, class: gr32bit } + - { id: 3, class: addr64bit } + - { id: 4, class: fp32bit } + - { id: 5, class: fp32bit } + - { id: 6, class: fp32bit } + - { id: 7, class: fp32bit } + - { id: 8, class: addr64bit } + - { id: 9, class: addr64bit } + - { id: 10, class: addr64bit } +frameInfo: + maxAlignment: 1 +machineFunctionInfo: {} +body: | + bb.0: + %0:gr64bit = LLGF undef %1:addr64bit, 0, $noreg :: (load 4 from `i32* undef`) + %6:fp32bit = LEFR %0.subreg_l32 + %3:addr64bit = COPY %0 + %3:addr64bit = MGHI %3, 12 + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $f0d, 12, implicit-def dead early-clobber $f1d, 12, implicit-def dead early-clobber $f2d, 12, implicit-def dead early-clobber $f3d, 12, implicit-def dead early-clobber $f4d, 12, implicit-def dead early-clobber $f5d, 12, implicit-def dead early-clobber $f6d, 12, implicit-def dead early-clobber $f7d, 12, implicit-def dead early-clobber $f8d, 12, implicit-def dead early-clobber $f9d, 12, implicit-def dead early-clobber $f10d, 12, implicit-def dead early-clobber $f11d, 12, implicit-def dead early-clobber $f12d, 12, implicit-def dead early-clobber $f13d, 12, implicit-def dead early-clobber $f14d, 12, implicit-def dead early-clobber $f14d, 12, implicit-def dead early-clobber $f15d + %7:fp32bit = VL32 %3, 4, $noreg + %6:fp32bit = contract nofpexcept SEB %6, $noreg, 8, $noreg, implicit-def dead $cc, implicit $fpc + %7:fp32bit = contract nofpexcept SEB %7, undef %8:addr64bit, 0, $noreg, implicit-def dead $cc, implicit $fpc + VST32 %6, undef %9:addr64bit, 0, $noreg :: (store 4 into `float* undef`) + VST32 %7, undef %10:addr64bit, 0, $noreg :: (store 4 into `float* undef`) + +... Index: llvm/test/CodeGen/SystemZ/foldmemop-msc.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/SystemZ/foldmemop-msc.mir @@ -0,0 +1,219 @@ +# RUN: llc -mtriple=s390x-linux-gnu -mcpu=z14 -start-before=greedy %s -o - \ +# RUN: | FileCheck %s +# +# Test folding of a memory operand into logical compare with an immediate. + +--- | + define i32 @fun0(i32* %src, i32 %arg) { ret i32 0 } + define i64 @fun1(i64* %src, i64 %arg) { ret i64 0 } + define i32 @fun2(i32* %src, i32 %arg) { ret i32 0 } + define i64 @fun3(i64* %src, i64 %arg) { ret i64 0 } +... + + +# CHECK-LABEL: fun0: +# CHECK-LABEL: .LBB0_2: +# CHECK: msc %r0, 164(%r15) # 4-byte Folded Reload +--- +name: fun0 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: grx32bit } + - { id: 1, class: grx32bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr32bit } + - { id: 4, class: grx32bit } + - { id: 5, class: grx32bit } + - { id: 6, class: gr32bit } + - { id: 7, class: gr32bit } + - { id: 8, class: gr32bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3l', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3l + + %3:gr32bit = COPY $r3l + %2:addr64bit = COPY $r2d + %6:gr32bit = LHIMux 0 + CHIMux %3, 0, implicit-def $cc + %8:gr32bit = LHIMux 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:gr32bit = LMux %2, 0, $noreg :: (load 4 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + %6:gr32bit = MSRKC %8, %6, implicit-def $cc + %6:gr32bit = LOCHIMux %6, 1, 14, 6, implicit killed $cc + %7:gr32bit = NRK %3, %6, implicit-def dead $cc + $r2l = COPY %7 + Return implicit $r2l + +... + + +# CHECK-LABEL: fun1: +# CHECK-LABEL: .LBB1_2: +# CHECK: msc %r0, 164(%r15) # 4-byte Folded Reload +--- +name: fun1 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: grx32bit } + - { id: 1, class: grx32bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr32bit } + - { id: 4, class: grx32bit } + - { id: 5, class: grx32bit } + - { id: 6, class: gr32bit } + - { id: 7, class: gr32bit } + - { id: 8, class: gr32bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3l', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3l + + %3:gr32bit = COPY $r3l + %2:addr64bit = COPY $r2d + %6:gr32bit = LHIMux 0 + CHIMux %3, 0, implicit-def $cc + %8:gr32bit = LHIMux 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:gr32bit = LMux %2, 0, $noreg :: (load 4 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + %6:gr32bit = MSRKC %6, %8, implicit-def $cc + %6:gr32bit = LOCHIMux %6, 1, 14, 6, implicit killed $cc + %7:gr32bit = NRK %3, %6, implicit-def dead $cc + $r2l = COPY %7 + Return implicit $r2l + +... + + +# CHECK-LABEL: fun2: +# CHECK-LABEL: .LBB2_2: +# CHECK: msgc %r0, 168(%r15) # 8-byte Folded Reload +--- +name: fun2 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: gr64bit } + - { id: 1, class: gr64bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr64bit } + - { id: 4, class: gr64bit } + - { id: 5, class: gr64bit } + - { id: 6, class: gr64bit } + - { id: 7, class: gr64bit } + - { id: 8, class: gr64bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3d', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3d + + %3:gr64bit = COPY $r3d + %2:addr64bit = COPY $r2d + %6:gr64bit = LGHI 0 + CGHI %3, 0, implicit-def $cc + %8:gr64bit = LGHI 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:gr64bit = LG %2, 0, $noreg :: (load 8 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + %6:gr64bit = MSGRKC %8, %6, implicit-def $cc + %6:gr64bit = LOCGHI %6, 1, 14, 6, implicit killed $cc + %7:gr64bit = NGRK %3, %6, implicit-def dead $cc + $r2d = COPY %7 + Return implicit $r2d + +... + + +# CHECK-LABEL: fun3: +# CHECK-LABEL: .LBB3_2: +# CHECK: msgc %r0, 168(%r15) # 8-byte Folded Reload +--- +name: fun3 +alignment: 16 +tracksRegLiveness: true +registers: + - { id: 0, class: gr64bit } + - { id: 1, class: gr64bit } + - { id: 2, class: addr64bit } + - { id: 3, class: gr64bit } + - { id: 4, class: gr64bit } + - { id: 5, class: gr64bit } + - { id: 6, class: gr64bit } + - { id: 7, class: gr64bit } + - { id: 8, class: gr64bit } +liveins: + - { reg: '$r2d', virtual-reg: '%2' } + - { reg: '$r3d', virtual-reg: '%3' } +frameInfo: + maxAlignment: 1 + hasOpaqueSPAdjustment: true +machineFunctionInfo: {} +body: | + bb.0: + successors: %bb.1(0x30000000), %bb.2(0x50000000) + liveins: $r2d, $r3d + + %3:gr64bit = COPY $r3d + %2:addr64bit = COPY $r2d + %6:gr64bit = LGHI 0 + CGHI %3, 0, implicit-def $cc + %8:gr64bit = LGHI 0 + BRC 14, 6, %bb.2, implicit killed $cc + J %bb.1 + + bb.1: + %8:gr64bit = LG %2, 0, $noreg :: (load 8 from %ir.src) + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + + bb.2: + INLINEASM &"", 1, 12, implicit-def dead early-clobber $r0d, 12, implicit-def dead early-clobber $r1d, 12, implicit-def dead early-clobber $r2d, 12, implicit-def dead early-clobber $r3d, 12, implicit-def dead early-clobber $r4d, 12, implicit-def dead early-clobber $r5d, 12, implicit-def dead early-clobber $r6d, 12, implicit-def dead early-clobber $r7d, 12, implicit-def dead early-clobber $r8d, 12, implicit-def dead early-clobber $r9d, 12, implicit-def dead early-clobber $r10d, 12, implicit-def dead early-clobber $r11d, 12, implicit-def dead early-clobber $r12d, 12, implicit-def dead early-clobber $r13d, 12, implicit-def dead early-clobber $r14d, 12, implicit-def early-clobber $r15d + %6:gr64bit = MSGRKC %6, %8, implicit-def $cc + %6:gr64bit = LOCGHI %6, 1, 14, 6, implicit killed $cc + %7:gr64bit = NGRK %3, %6, implicit-def dead $cc + $r2d = COPY %7 + Return implicit $r2d + +...