[SystemZ] Add comparisons of large immediates using high words
authorRichard Sandiford <rsandifo@linux.vnet.ibm.com>
Tue, 1 Oct 2013 14:56:23 +0000 (14:56 +0000)
committerRichard Sandiford <rsandifo@linux.vnet.ibm.com>
Tue, 1 Oct 2013 14:56:23 +0000 (14:56 +0000)
There are no corresponding patterns for small immediates because they would
prevent the use of fused compare-and-branch instructions.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191775 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/SystemZ/SystemZInstrInfo.cpp
lib/Target/SystemZ/SystemZInstrInfo.td
test/CodeGen/SystemZ/asm-18.ll
test/MC/Disassembler/SystemZ/insns.txt
test/MC/SystemZ/insn-bad-z196.s
test/MC/SystemZ/insn-bad.s
test/MC/SystemZ/insn-good-z196.s

index acefd9c8fea0115c654abfe8ee5830c737d22246..9b50a3c684c1769574c01ade47f0050e08bf530c 100644 (file)
@@ -966,6 +966,14 @@ SystemZInstrInfo::expandPostRAPseudo(MachineBasicBlock::iterator MI) const {
     expandRIPseudo(MI, SystemZ::AFI, SystemZ::AIH, false);
     return true;
 
+  case SystemZ::CFIMux:
+    expandRIPseudo(MI, SystemZ::CFI, SystemZ::CIH, false);
+    return true;
+
+  case SystemZ::CLFIMux:
+    expandRIPseudo(MI, SystemZ::CLFI, SystemZ::CLIH, false);
+    return true;
+
   case SystemZ::RISBMux: {
     bool DestIsHigh = isHighReg(MI->getOperand(0).getReg());
     bool SrcIsHigh = isHighReg(MI->getOperand(2).getReg());
index 986e77f17f926d30235675f5e44edec678bb87e0..f7dbd094fa0d3f9aa28d00c88a4627ed6171e002 100644 (file)
@@ -1076,8 +1076,13 @@ let Defs = [CC], CCValues = 0xE in {
   def CHI  : CompareRI<"chi",  0xA7E, z_scmp, GR32, imm32sx16>;
   def CGHI : CompareRI<"cghi", 0xA7F, z_scmp, GR64, imm64sx16>;
 
-  // Comparison with a signed 32-bit immediate.
+  // Comparison with a signed 32-bit immediate.  CFIMux expands to CFI or CIH,
+  // depending on the choice of register.
+  def CFIMux : CompareRIPseudo<z_scmp, GRX32, simm32>,
+               Requires<[FeatureHighWord]>;
   def CFI  : CompareRIL<"cfi",  0xC2D, z_scmp, GR32, simm32>;
+  def CIH  : CompareRIL<"cih",  0xCCD, z_scmp, GRH32, simm32>,
+             Requires<[FeatureHighWord]>;
   def CGFI : CompareRIL<"cgfi", 0xC2C, z_scmp, GR64, imm64sx32>;
 
   // Comparison with memory.
@@ -1106,8 +1111,13 @@ let Defs = [CC], CCValues = 0xE, IsLogical = 1 in {
   def CLGFR : CompareRRE<"clgf", 0xB931, null_frag, GR64, GR32>;
   def CLGR  : CompareRRE<"clg",  0xB921, z_ucmp,    GR64, GR64>;
 
-  // Comparison with a signed 32-bit immediate.
+  // Comparison with an unsigned 32-bit immediate.  CLFIMux expands to CLFI
+  // or CLIH, depending on the choice of register.
+  def CLFIMux : CompareRIPseudo<z_ucmp, GRX32, uimm32>,
+                Requires<[FeatureHighWord]>;
   def CLFI  : CompareRIL<"clfi",  0xC2F, z_ucmp, GR32, uimm32>;
+  def CLIH  : CompareRIL<"clih",  0xCCF, z_ucmp, GR32, uimm32>,
+              Requires<[FeatureHighWord]>;
   def CLGFI : CompareRIL<"clgfi", 0xC2E, z_ucmp, GR64, imm64zx32>;
 
   // Comparison with memory.
index e16bf65c3e8b6024c50b4f7808537b1a35723c0c..d39de6d6550bb88b21a1fdea2ef984c8d657de58 100644 (file)
@@ -669,3 +669,37 @@ define void @f30() {
   call void asm sideeffect "stepd $0", "r"(i32 %add3)
   ret void
 }
+
+; Test large immediate comparison involving high registers.
+define i32 @f31() {
+; CHECK-LABEL: f31:
+; CHECK: stepa [[REG1:%r[0-5]]]
+; CHECK: cih [[REG1]], 1000000000
+; CHECK: stepb [[REG2:%r[0-5]]]
+; CHECK: clih [[REG2]], 1000000000
+; CHECK: br %r14
+  %res1 = call i32 asm "stepa $0", "=h"()
+  %cmp1 = icmp sle i32 %res1, 1000000000
+  %sel1 = select i1 %cmp1, i32 0, i32 1
+  %res2 = call i32 asm "stepb $0, $1", "=h,r"(i32 %sel1)
+  %cmp2 = icmp ule i32 %res2, 1000000000
+  %sel2 = select i1 %cmp2, i32 0, i32 1
+  ret i32 %sel2
+}
+
+; Test large immediate comparison involving low registers.
+define i32 @f32() {
+; CHECK-LABEL: f32:
+; CHECK: stepa [[REG1:%r[0-5]]]
+; CHECK: cfi [[REG1]], 1000000000
+; CHECK: stepb [[REG2:%r[0-5]]]
+; CHECK: clfi [[REG2]], 1000000000
+; CHECK: br %r14
+  %res1 = call i32 asm "stepa $0", "=r"()
+  %cmp1 = icmp sle i32 %res1, 1000000000
+  %sel1 = select i1 %cmp1, i32 0, i32 1
+  %res2 = call i32 asm "stepb $0, $1", "=r,r"(i32 %sel1)
+  %cmp2 = icmp ule i32 %res2, 1000000000
+  %sel2 = select i1 %cmp2, i32 0, i32 1
+  ret i32 %sel2
+}
index 2f2e7fa0cd1cd460f44c365e088989dbbd5ee261..f88531b2cdf0a586dd9599506815de6843b10e8f 100644 (file)
 # CHECK: chy %r15, 0
 0xe3 0xf0 0x00 0x00 0x00 0x79
 
+# CHECK: cih %r0, -2147483648
+0xcc 0x0d 0x80 0x00 0x00 0x00
+
+# CHECK: cih %r0, -1
+0xcc 0x0d 0xff 0xff 0xff 0xff
+
+# CHECK: cih %r0, 0
+0xcc 0x0d 0x00 0x00 0x00 0x00
+
+# CHECK: cih %r0, 1
+0xcc 0x0d 0x00 0x00 0x00 0x01
+
+# CHECK: cih %r0, 2147483647
+0xcc 0x0d 0x7f 0xff 0xff 0xff
+
+# CHECK: cih %r15, 0
+0xcc 0xfd 0x00 0x00 0x00 0x00
+
 # CHECK: clc 0(1), 0
 0xd5 0x00 0x00 0x00 0x00 0x00
 
 # CHECK: cli 4095(%r15), 42
 0x95 0x2a 0xff 0xff
 
+# CHECK: clih %r0, 0
+0xcc 0x0f 0x00 0x00 0x00 0x00
+
+# CHECK: clih %r0, 1
+0xcc 0x0f 0x00 0x00 0x00 0x01
+
+# CHECK: clih %r0, 4294967295
+0xcc 0x0f 0xff 0xff 0xff 0xff
+
+# CHECK: clih %r15, 0
+0xcc 0xff 0x00 0x00 0x00 0x00
+
 # CHECK: cliy -524288, 0
 0xeb 0x00 0x00 0x00 0x80 0x55
 
index 24640018a52390f7b249d38fa96bd8d72e1dca49..e387f149fd122319f8f966f0d3e6087f24c86db6 100644 (file)
        aih     %r0, (-1 << 31) - 1
        aih     %r0, (1 << 31)
 
+#CHECK: error: invalid operand
+#CHECK: cih    %r0, (-1 << 31) - 1
+#CHECK: error: invalid operand
+#CHECK: cih    %r0, (1 << 31)
+
+       cih     %r0, (-1 << 31) - 1
+       cih     %r0, (1 << 31)
+
+#CHECK: error: invalid operand
+#CHECK: clih   %r0, -1
+#CHECK: error: invalid operand
+#CHECK: clih   %r0, (1 << 32)
+
+       clih    %r0, -1
+       clih    %r0, (1 << 32)
+
 #CHECK: error: invalid operand
 #CHECK: fidbra %f0, 0, %f0, -1
 #CHECK: error: invalid operand
index eadb9f099717bdc51cafb311b06ea0485a7e59f5..8de20612caad016da22cb6a60e5b1cc1df44ed68 100644 (file)
        chy     %r0, -524289
        chy     %r0, 524288
 
+#CHECK: error: {{(instruction requires: high-word)?}}
+#CHECK: cih    %r0, 0
+
+       cih     %r0, 0
+
 #CHECK: error: invalid operand
 #CHECK: cij    %r0, -129, 0, 0
 #CHECK: error: invalid operand
        cli     0, -1
        cli     0, 256
 
+#CHECK: error: {{(instruction requires: high-word)?}}
+#CHECK: clih   %r0, 0
+
+       clih    %r0, 0
+
 #CHECK: error: invalid operand
 #CHECK: clij   %r0, -1, 0, 0
 #CHECK: error: invalid operand
index 2bc27bd58a0f54d9266f762b3d5fb8b74b8e809f..93687ea81f6e932984a9eb6f12905715838430c4 100644 (file)
        ark     %r15,%r0,%r0
        ark     %r7,%r8,%r9
 
+#CHECK: cih    %r0, -2147483648        # encoding: [0xcc,0x0d,0x80,0x00,0x00,0x00]
+#CHECK: cih    %r0, -1                 # encoding: [0xcc,0x0d,0xff,0xff,0xff,0xff]
+#CHECK: cih    %r0, 0                  # encoding: [0xcc,0x0d,0x00,0x00,0x00,0x00]
+#CHECK: cih    %r0, 1                  # encoding: [0xcc,0x0d,0x00,0x00,0x00,0x01]
+#CHECK: cih    %r0, 2147483647         # encoding: [0xcc,0x0d,0x7f,0xff,0xff,0xff]
+#CHECK: cih    %r15, 0                 # encoding: [0xcc,0xfd,0x00,0x00,0x00,0x00]
+
+       cih     %r0, -1 << 31
+       cih     %r0, -1
+       cih     %r0, 0
+       cih     %r0, 1
+       cih     %r0, (1 << 31) - 1
+       cih     %r15, 0
+
+#CHECK: clih   %r0, 0                  # encoding: [0xcc,0x0f,0x00,0x00,0x00,0x00]
+#CHECK: clih   %r0, 1                  # encoding: [0xcc,0x0f,0x00,0x00,0x00,0x01]
+#CHECK: clih   %r0, 4294967295         # encoding: [0xcc,0x0f,0xff,0xff,0xff,0xff]
+#CHECK: clih   %r15, 0                 # encoding: [0xcc,0xff,0x00,0x00,0x00,0x00]
+
+       clih    %r0, 0
+       clih    %r0, 1
+       clih    %r0, (1 << 32) - 1
+       clih    %r15, 0
+
 #CHECK: fidbra %f0, 0, %f0, 0          # encoding: [0xb3,0x5f,0x00,0x00]
 #CHECK: fidbra %f0, 0, %f0, 15         # encoding: [0xb3,0x5f,0x0f,0x00]
 #CHECK: fidbra %f0, 0, %f15, 0         # encoding: [0xb3,0x5f,0x00,0x0f]