[AMDGPU][MC][GFX10] Corrected constant bus limit for 64-bit shift instructions
authorDmitry Preobrazhensky <dmitry.preobrazhensky@amd.com>
Mon, 2 Sep 2019 12:50:05 +0000 (12:50 +0000)
committerDmitry Preobrazhensky <dmitry.preobrazhensky@amd.com>
Mon, 2 Sep 2019 12:50:05 +0000 (12:50 +0000)
See bug 42744: https://bugs.llvm.org/show_bug.cgi?id=42744

Reviewers: atamazov, arsenm

Differential Revision: https://reviews.llvm.org/D65228

llvm-svn: 370652

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/test/MC/AMDGPU/gfx10-constant-bus.s
llvm/test/MC/AMDGPU/vop3-literal.s

index 77399e34af7edbcc3e8c0e44ec1e51c3ff172925..ab9e0a9d7077f191ee7ec48a372f5610c8655b7a 100644 (file)
@@ -1309,6 +1309,7 @@ private:
   bool validateOpSel(const MCInst &Inst);
   bool validateVccOperand(unsigned Reg) const;
   bool validateVOP3Literal(const MCInst &Inst) const;
+  unsigned getConstantBusLimit(unsigned Opcode) const;
   bool usesConstantBus(const MCInst &Inst, unsigned OpIdx);
   bool isInlineConstant(const MCInst &Inst, unsigned OpIdx) const;
   unsigned findImplicitSGPRReadInVOP(const MCInst &Inst) const;
@@ -2703,6 +2704,27 @@ bool AMDGPUAsmParser::isInlineConstant(const MCInst &Inst,
   }
 }
 
+unsigned AMDGPUAsmParser::getConstantBusLimit(unsigned Opcode) const {
+  if (!isGFX10())
+    return 1;
+
+  switch (Opcode) {
+  // 64-bit shift instructions can use only one scalar value input
+  case AMDGPU::V_LSHLREV_B64:
+  case AMDGPU::V_LSHLREV_B64_gfx10:
+  case AMDGPU::V_LSHL_B64:
+  case AMDGPU::V_LSHRREV_B64:
+  case AMDGPU::V_LSHRREV_B64_gfx10:
+  case AMDGPU::V_LSHR_B64:
+  case AMDGPU::V_ASHRREV_I64:
+  case AMDGPU::V_ASHRREV_I64_gfx10:
+  case AMDGPU::V_ASHR_I64:
+    return 1;
+  default:
+    return 2;
+  }
+}
+
 bool AMDGPUAsmParser::usesConstantBus(const MCInst &Inst, unsigned OpIdx) {
   const MCOperand &MO = Inst.getOperand(OpIdx);
   if (MO.isImm()) {
@@ -2788,10 +2810,7 @@ bool AMDGPUAsmParser::validateConstantBusLimitations(const MCInst &Inst) {
   }
   ConstantBusUseCount += NumLiterals;
 
-  if (isGFX10())
-    return ConstantBusUseCount <= 2;
-
-  return ConstantBusUseCount <= 1;
+  return ConstantBusUseCount <= getConstantBusLimit(Opcode);
 }
 
 bool AMDGPUAsmParser::validateEarlyClobberLimitations(const MCInst &Inst) {
index 2fc844582e51fa72332ac8b29bd785ff345eeb32..685a7c04f0c342dafff98a8f90c8a10f46b5d43d 100644 (file)
@@ -2,7 +2,7 @@
 // RUN: not llvm-mc -arch=amdgcn -mcpu=gfx1010 -show-encoding %s 2>&1 | FileCheck -check-prefix=GFX10-ERR %s
 
 //-----------------------------------------------------------------------------------------
-// On GFX10 we can use two scalar operands
+// On GFX10 we can use two scalar operands (except for 64-bit shift instructions)
 
 v_add_f32 v0, s0, s1
 // GFX10: v_add_f32_e64 v0, s0, s1        ; encoding: [0x00,0x00,0x03,0xd5,0x00,0x02,0x00,0x00]
@@ -13,6 +13,15 @@ v_madak_f32 v0, s0, v1, 42.42
 v_med3_f32 v0, s0, s0, s1
 // GFX10: v_med3_f32 v0, s0, s0, s1       ; encoding: [0x00,0x00,0x57,0xd5,0x00,0x00,0x04,0x00]
 
+//-----------------------------------------------------------------------------------------
+// 64-bit shift instructions can use only one scalar value input
+
+v_ashrrev_i64 v[0:1], 0x100, s[0:1]
+// GFX10-ERR: error: invalid operand (violates constant bus restrictions)
+
+v_ashrrev_i64 v[0:1], s2, s[0:1]
+// GFX10-ERR: error: invalid operand (violates constant bus restrictions)
+
 //-----------------------------------------------------------------------------------------
 // v_div_fmas implicitly reads VCC, so only one scalar operand is possible
 
@@ -38,6 +47,9 @@ v_div_fmas_f64 v[5:6], v[1:2], s[2:3], 0x123456
 // v_mad_u64_u32 has operands of different sizes.
 // When these operands are literals, they are counted as 2 scalar values even if literals are identical.
 
+v_lshlrev_b64 v[5:6], 0x3f717273, 0x3f717273
+// GFX10-ERR: error: invalid operand (violates constant bus restrictions)
+
 v_mad_u64_u32 v[5:6], s12, v1, 0x12345678, 0x12345678
 // GFX10: v_mad_u64_u32 v[5:6], s12, v1, 0x12345678, 0x12345678 ; encoding: [0x05,0x0c,0x76,0xd5,0x01,0xff,0xfd,0x03,0x78,0x56,0x34,0x12]
 
index eef30fe0097ba969c61972ca904a1657c8559ef6..99265352f0cec3330f439aea93a7c421dd5dd2f4 100644 (file)
@@ -305,10 +305,6 @@ v_lshlrev_b64 v[5:6], v1, 0x3f717273
 // GFX10: v_lshlrev_b64 v[5:6], v1, 0x3f717273 ; encoding: [0x05,0x00,0xff,0xd6,0x01,0xff,0x01,0x00,0x73,0x72,0x71,0x3f]
 // GFX9-ERR: error: invalid literal operand
 
-v_lshlrev_b64 v[5:6], 0x3f717273, 0x3f717273
-// GFX10: v_lshlrev_b64 v[5:6], 0x3f717273, 0x3f717273 ; encoding: [0x05,0x00,0xff,0xd6,0xff,0xfe,0x01,0x00,0x73,0x72,0x71,0x3f]
-// GFX9-ERR: error: invalid literal operand
-
 v_fma_mix_f32 v5, 0x123, v2, v3
 // GFX10: v_fma_mix_f32 v5, 0x123, v2, v3 ; encoding: [0x05,0x00,0x20,0xcc,0xff,0x04,0x0e,0x04,0x23,0x01,0x00,0x00]