[llvm] r282145 - [AMDGPU][mc] Add support for absolute expressions in DPP modifiers.
Artem Tamazov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 22 04:47:23 PDT 2016
Author: artem.tamazov
Date: Thu Sep 22 06:47:21 2016
New Revision: 282145
URL: http://llvm.org/viewvc/llvm-project?rev=282145&view=rev
Log:
[AMDGPU][mc] Add support for absolute expressions in DPP modifiers.
Also added range checking for DPP attributes.
Assembler tests added as well.
Differential Revision: https://reviews.llvm.org/D24755
Added:
llvm/trunk/test/MC/AMDGPU/vop_dpp_expr.s
Modified:
llvm/trunk/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
Modified: llvm/trunk/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp?rev=282145&r1=282144&r2=282145&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp Thu Sep 22 06:47:21 2016
@@ -2734,8 +2734,10 @@ AMDGPUAsmParser::parseDPPCtrl(OperandVec
if (Prefix == "row_mirror") {
Int = 0x140;
+ Parser.Lex();
} else if (Prefix == "row_half_mirror") {
Int = 0x141;
+ Parser.Lex();
} else {
// Check to prevent parseDPPCtrlOps from eating invalid tokens
if (Prefix != "quad_perm"
@@ -2759,60 +2761,46 @@ AMDGPUAsmParser::parseDPPCtrl(OperandVec
Parser.Lex();
if (getLexer().isNot(AsmToken::LBrac))
return MatchOperand_ParseFail;
-
Parser.Lex();
- if (getLexer().isNot(AsmToken::Integer))
- return MatchOperand_ParseFail;
- Int = getLexer().getTok().getIntVal();
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Comma))
+ if (getParser().parseAbsoluteExpression(Int) || !(0 <= Int && Int <=3))
return MatchOperand_ParseFail;
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Integer))
- return MatchOperand_ParseFail;
- Int += (getLexer().getTok().getIntVal() << 2);
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Comma))
- return MatchOperand_ParseFail;
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Integer))
- return MatchOperand_ParseFail;
- Int += (getLexer().getTok().getIntVal() << 4);
+ for (int i = 0; i < 3; ++i) {
+ if (getLexer().isNot(AsmToken::Comma))
+ return MatchOperand_ParseFail;
+ Parser.Lex();
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Comma))
- return MatchOperand_ParseFail;
- Parser.Lex();
- if (getLexer().isNot(AsmToken::Integer))
- return MatchOperand_ParseFail;
- Int += (getLexer().getTok().getIntVal() << 6);
+ int64_t Temp;
+ if (getParser().parseAbsoluteExpression(Temp) || !(0 <= Temp && Temp <=3))
+ return MatchOperand_ParseFail;
+ const int shift = i*2 + 2;
+ Int += (Temp << shift);
+ }
- Parser.Lex();
if (getLexer().isNot(AsmToken::RBrac))
return MatchOperand_ParseFail;
+ Parser.Lex();
} else {
// sel:%d
Parser.Lex();
- if (getLexer().isNot(AsmToken::Integer))
+ if (getParser().parseAbsoluteExpression(Int))
return MatchOperand_ParseFail;
- Int = getLexer().getTok().getIntVal();
- if (Prefix == "row_shl") {
+ if (Prefix == "row_shl" && 1 <= Int && Int <= 15) {
Int |= 0x100;
- } else if (Prefix == "row_shr") {
+ } else if (Prefix == "row_shr" && 1 <= Int && Int <= 15) {
Int |= 0x110;
- } else if (Prefix == "row_ror") {
+ } else if (Prefix == "row_ror" && 1 <= Int && Int <= 15) {
Int |= 0x120;
- } else if (Prefix == "wave_shl") {
+ } else if (Prefix == "wave_shl" && 1 == Int) {
Int = 0x130;
- } else if (Prefix == "wave_rol") {
+ } else if (Prefix == "wave_rol" && 1 == Int) {
Int = 0x134;
- } else if (Prefix == "wave_shr") {
+ } else if (Prefix == "wave_shr" && 1 == Int) {
Int = 0x138;
- } else if (Prefix == "wave_ror") {
+ } else if (Prefix == "wave_ror" && 1 == Int) {
Int = 0x13C;
} else if (Prefix == "row_bcast") {
if (Int == 15) {
@@ -2827,7 +2815,6 @@ AMDGPUAsmParser::parseDPPCtrl(OperandVec
}
}
}
- Parser.Lex(); // eat last token
Operands.push_back(AMDGPUOperand::CreateImm(this, Int, S, AMDGPUOperand::ImmTyDppCtrl));
return MatchOperand_Success;
Added: llvm/trunk/test/MC/AMDGPU/vop_dpp_expr.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AMDGPU/vop_dpp_expr.s?rev=282145&view=auto
==============================================================================
--- llvm/trunk/test/MC/AMDGPU/vop_dpp_expr.s (added)
+++ llvm/trunk/test/MC/AMDGPU/vop_dpp_expr.s Thu Sep 22 06:47:21 2016
@@ -0,0 +1,35 @@
+// RUN: llvm-mc -arch=amdgcn -mcpu=tonga -show-encoding %s | FileCheck %s --check-prefix=GCN --check-prefix=CIVI --check-prefix=VI
+
+zero = 0
+two = 2
+one = 1
+
+v_mov_b32 v0, v0 quad_perm:[0+zero,zero-2+two*two,1/one,1]
+// VI: v_mov_b32_dpp v0, v0 quad_perm:[0,2,1,1] row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x58,0x00,0xff]
+
+v_mov_b32 v0, v0 row_shl:two-1
+// VI: v_mov_b32_dpp v0, v0 row_shl:1 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x01,0x01,0xff]
+
+v_mov_b32 v0, v0 row_shr:0xe+one
+// VI: v_mov_b32_dpp v0, v0 row_shr:15 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x1f,0x01,0xff]
+
+v_mov_b32 v0, v0 row_ror:0x6*two
+// VI: v_mov_b32_dpp v0, v0 row_ror:12 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x2c,0x01,0xff]
+
+v_mov_b32 v0, v0 wave_shl:two/2
+// VI: v_mov_b32_dpp v0, v0 wave_shl:1 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x30,0x01,0xff]
+
+v_mov_b32 v0, v0 wave_rol:two-one
+// VI: v_mov_b32_dpp v0, v0 wave_rol:1 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x34,0x01,0xff]
+
+v_mov_b32 v0, v0 wave_shr:1+zero
+// VI: v_mov_b32_dpp v0, v0 wave_shr:1 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x38,0x01,0xff]
+
+v_mov_b32 v0, v0 wave_ror:two*2-3
+// VI: v_mov_b32_dpp v0, v0 wave_ror:1 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x3c,0x01,0xff]
+
+v_mov_b32 v0, v0 row_bcast:150/(two*2+zero/one+two*3)
+// VI: v_mov_b32_dpp v0, v0 row_bcast:15 row_mask:0xf bank_mask:0xf ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x42,0x01,0xff]
+
+v_mov_b32 v0, v0 quad_perm:[one,two+one,zero,2-one] row_mask:2*5 bank_mask:0x2-one bound_ctrl:1-1
+// VI: v_mov_b32_dpp v0, v0 quad_perm:[1,3,0,1] row_mask:0xa bank_mask:0x1 bound_ctrl:0 ; encoding: [0xfa,0x02,0x00,0x7e,0x00,0x4d,0x08,0xa1]
More information about the llvm-commits
mailing list