tint/transform: Polyfill bit-shift with RHS modulo

Fixed: tint:1453
Fixed: tint:1543
Change-Id: Idb5af752d7a3bb9e181cc47430ad4ddfb707873d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108440
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2022-11-03 19:15:17 +00:00
committed by Dawn LUCI CQ
parent 91e27f25f9
commit 02f04d914d
47 changed files with 345 additions and 157 deletions

View File

@@ -2,6 +2,6 @@
void f() {
const int a = 1;
const uint b = 2u;
const int r = (a << b);
const int r = (a << (b & 31u));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const int a = 1;
const uint b = 2u;
const int r = (a << b);
const int r = (a << (b & 31u));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
int a = 1;
uint b = 2u;
int r = (a << b);
int r = (a << (b & 31u));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
int const a = 1;
uint const b = 2u;
int const r = as_type<int>((as_type<uint>(a) << b));
int const r = as_type<int>((as_type<uint>(a) << (b & 31u)));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 10
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -14,8 +14,10 @@
%int_1 = OpConstant %int 1
%uint = OpTypeInt 32 0
%uint_2 = OpConstant %uint 2
%uint_31 = OpConstant %uint 31
%f = OpFunction %void None %1
%4 = OpLabel
%9 = OpShiftLeftLogical %int %int_1 %uint_2
%10 = OpBitwiseAnd %uint %uint_2 %uint_31
%11 = OpShiftLeftLogical %int %int_1 %10
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const uint a = 1u;
const uint b = 2u;
const uint r = (a << b);
const uint r = (a << (b & 31u));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const uint a = 1u;
const uint b = 2u;
const uint r = (a << b);
const uint r = (a << (b & 31u));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
uint a = 1u;
uint b = 2u;
uint r = (a << b);
uint r = (a << (b & 31u));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
uint const a = 1u;
uint const b = 2u;
uint const r = (a << b);
uint const r = (a << (b & 31u));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 9
; Bound: 11
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,8 +13,10 @@
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_31 = OpConstant %uint 31
%f = OpFunction %void None %1
%4 = OpLabel
%8 = OpShiftLeftLogical %uint %uint_1 %uint_2
%9 = OpBitwiseAnd %uint %uint_2 %uint_31
%10 = OpShiftLeftLogical %uint %uint_1 %9
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const int3 a = int3(1, 2, 3);
const uint3 b = uint3(4u, 5u, 6u);
const int3 r = (a << b);
const int3 r = (a << (b & (31u).xxx));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const int3 a = int3(1, 2, 3);
const uint3 b = uint3(4u, 5u, 6u);
const int3 r = (a << b);
const int3 r = (a << (b & (31u).xxx));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
ivec3 a = ivec3(1, 2, 3);
uvec3 b = uvec3(4u, 5u, 6u);
ivec3 r = (a << b);
ivec3 r = (a << (b & uvec3(31u)));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
int3 const a = int3(1, 2, 3);
uint3 const b = uint3(4u, 5u, 6u);
int3 const r = as_type<int3>((as_type<uint3>(a) << b));
int3 const r = as_type<int3>((as_type<uint3>(a) << (b & uint3(31u))));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Bound: 21
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -22,8 +22,11 @@
%uint_5 = OpConstant %uint 5
%uint_6 = OpConstant %uint 6
%16 = OpConstantComposite %v3uint %uint_4 %uint_5 %uint_6
%uint_31 = OpConstant %uint 31
%18 = OpConstantComposite %v3uint %uint_31 %uint_31 %uint_31
%f = OpFunction %void None %1
%4 = OpLabel
%17 = OpShiftLeftLogical %v3int %10 %16
%19 = OpBitwiseAnd %v3uint %16 %18
%20 = OpShiftLeftLogical %v3int %10 %19
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const uint3 a = uint3(1u, 2u, 3u);
const uint3 b = uint3(4u, 5u, 6u);
const uint3 r = (a << b);
const uint3 r = (a << (b & (31u).xxx));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const uint3 a = uint3(1u, 2u, 3u);
const uint3 b = uint3(4u, 5u, 6u);
const uint3 r = (a << b);
const uint3 r = (a << (b & (31u).xxx));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
uvec3 a = uvec3(1u, 2u, 3u);
uvec3 b = uvec3(4u, 5u, 6u);
uvec3 r = (a << b);
uvec3 r = (a << (b & uvec3(31u)));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
uint3 const a = uint3(1u, 2u, 3u);
uint3 const b = uint3(4u, 5u, 6u);
uint3 const r = (a << b);
uint3 const r = (a << (b & uint3(31u)));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 16
; Bound: 19
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -20,8 +20,11 @@
%uint_5 = OpConstant %uint 5
%uint_6 = OpConstant %uint 6
%14 = OpConstantComposite %v3uint %uint_4 %uint_5 %uint_6
%uint_31 = OpConstant %uint 31
%16 = OpConstantComposite %v3uint %uint_31 %uint_31 %uint_31
%f = OpFunction %void None %1
%4 = OpLabel
%15 = OpShiftLeftLogical %v3uint %10 %14
%17 = OpBitwiseAnd %v3uint %14 %16
%18 = OpShiftLeftLogical %v3uint %10 %17
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const int a = 1;
const uint b = 2u;
const int r = (a >> b);
const int r = (a >> (b & 31u));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const int a = 1;
const uint b = 2u;
const int r = (a >> b);
const int r = (a >> (b & 31u));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
int a = 1;
uint b = 2u;
int r = (a >> b);
int r = (a >> (b & 31u));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
int const a = 1;
uint const b = 2u;
int const r = (a >> b);
int const r = (a >> (b & 31u));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 10
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -14,8 +14,10 @@
%int_1 = OpConstant %int 1
%uint = OpTypeInt 32 0
%uint_2 = OpConstant %uint 2
%uint_31 = OpConstant %uint 31
%f = OpFunction %void None %1
%4 = OpLabel
%9 = OpShiftRightArithmetic %int %int_1 %uint_2
%10 = OpBitwiseAnd %uint %uint_2 %uint_31
%11 = OpShiftRightArithmetic %int %int_1 %10
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const uint a = 1u;
const uint b = 2u;
const uint r = (a >> b);
const uint r = (a >> (b & 31u));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const uint a = 1u;
const uint b = 2u;
const uint r = (a >> b);
const uint r = (a >> (b & 31u));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
uint a = 1u;
uint b = 2u;
uint r = (a >> b);
uint r = (a >> (b & 31u));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
uint const a = 1u;
uint const b = 2u;
uint const r = (a >> b);
uint const r = (a >> (b & 31u));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 9
; Bound: 11
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -13,8 +13,10 @@
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_31 = OpConstant %uint 31
%f = OpFunction %void None %1
%4 = OpLabel
%8 = OpShiftRightLogical %uint %uint_1 %uint_2
%9 = OpBitwiseAnd %uint %uint_2 %uint_31
%10 = OpShiftRightLogical %uint %uint_1 %9
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const int3 a = int3(1, 2, 3);
const uint3 b = uint3(4u, 5u, 6u);
const int3 r = (a >> b);
const int3 r = (a >> (b & (31u).xxx));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const int3 a = int3(1, 2, 3);
const uint3 b = uint3(4u, 5u, 6u);
const int3 r = (a >> b);
const int3 r = (a >> (b & (31u).xxx));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
ivec3 a = ivec3(1, 2, 3);
uvec3 b = uvec3(4u, 5u, 6u);
ivec3 r = (a >> b);
ivec3 r = (a >> (b & uvec3(31u)));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
int3 const a = int3(1, 2, 3);
uint3 const b = uint3(4u, 5u, 6u);
int3 const r = (a >> b);
int3 const r = (a >> (b & uint3(31u)));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Bound: 21
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -22,8 +22,11 @@
%uint_5 = OpConstant %uint 5
%uint_6 = OpConstant %uint 6
%16 = OpConstantComposite %v3uint %uint_4 %uint_5 %uint_6
%uint_31 = OpConstant %uint 31
%18 = OpConstantComposite %v3uint %uint_31 %uint_31 %uint_31
%f = OpFunction %void None %1
%4 = OpLabel
%17 = OpShiftRightArithmetic %v3int %10 %16
%19 = OpBitwiseAnd %v3uint %16 %18
%20 = OpShiftRightArithmetic %v3int %10 %19
OpReturn
OpFunctionEnd

View File

@@ -2,6 +2,6 @@
void f() {
const uint3 a = uint3(1u, 2u, 3u);
const uint3 b = uint3(4u, 5u, 6u);
const uint3 r = (a >> b);
const uint3 r = (a >> (b & (31u).xxx));
return;
}

View File

@@ -2,6 +2,6 @@
void f() {
const uint3 a = uint3(1u, 2u, 3u);
const uint3 b = uint3(4u, 5u, 6u);
const uint3 r = (a >> b);
const uint3 r = (a >> (b & (31u).xxx));
return;
}

View File

@@ -3,7 +3,7 @@
void f() {
uvec3 a = uvec3(1u, 2u, 3u);
uvec3 b = uvec3(4u, 5u, 6u);
uvec3 r = (a >> b);
uvec3 r = (a >> (b & uvec3(31u)));
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

View File

@@ -4,7 +4,7 @@ using namespace metal;
kernel void f() {
uint3 const a = uint3(1u, 2u, 3u);
uint3 const b = uint3(4u, 5u, 6u);
uint3 const r = (a >> b);
uint3 const r = (a >> (b & uint3(31u)));
return;
}

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 16
; Bound: 19
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -20,8 +20,11 @@
%uint_5 = OpConstant %uint 5
%uint_6 = OpConstant %uint 6
%14 = OpConstantComposite %v3uint %uint_4 %uint_5 %uint_6
%uint_31 = OpConstant %uint 31
%16 = OpConstantComposite %v3uint %uint_31 %uint_31 %uint_31
%f = OpFunction %void None %1
%4 = OpLabel
%15 = OpShiftRightLogical %v3uint %10 %14
%17 = OpBitwiseAnd %v3uint %14 %16
%18 = OpShiftRightLogical %v3uint %10 %17
OpReturn
OpFunctionEnd