Browse Source

[spirv] Translate vector truncation and splatting (#502)

* [spirv] Translate vector truncation and splatting

* Also added tests for vector<|type|, |count|> format.

* [spirv] Remove duplicated vector splatting tests

Although they appear as binary operator tests, they are essentially
testing vector splatting, which we already have dedicated tests.
Lei Zhang 8 years ago
parent
commit
694c35a47e

+ 2 - 0
docs/SPIR-V.rst

@@ -174,6 +174,8 @@ Vectors and matrixes
 |``|type||row|x|column|``            | ``OpTypeMatrix %v |column|``       |
 +------------------------------------+------------------------------------+
 
+Note that vectors of size 1 are just translated into scalar values of the element types since SPIR-V mandates the size of vector to be at least 2.
+
 Structs
 +++++++
 

+ 23 - 7
tools/clang/lib/SPIRV/EmitSPIRVAction.cpp

@@ -924,14 +924,30 @@ public:
 
       return theBuilder.createCompositeConstruct(vecTypeId, elements);
     }
-    case CastKind::CK_HLSLVectorToScalarCast: {
-      // We should have already treated vectors of size 1 as scalars.
-      // So do nothing here.
-      if (hlsl::GetHLSLVecSize(subExpr->getType()) == 1) {
-        return doExpr(subExpr);
+    case CastKind::CK_HLSLVectorTruncationCast: {
+      const uint32_t toVecTypeId = typeTranslator.translateType(toType);
+      const uint32_t elemTypeId =
+          typeTranslator.translateType(hlsl::GetHLSLVecElementType(toType));
+      const auto toSize = hlsl::GetHLSLVecSize(toType);
+
+      const uint32_t composite = doExpr(subExpr);
+      llvm::SmallVector<uint32_t, 4> elements;
+
+      for (uint32_t i = 0; i < toSize; ++i) {
+        elements.push_back(
+            theBuilder.createCompositeExtract(elemTypeId, composite, {i}));
       }
-      emitError("vector to scalar cast unimplemented");
-      return 0;
+
+      if (toSize == 1) {
+        return elements.front();
+      }
+
+      return theBuilder.createCompositeConstruct(toVecTypeId, elements);
+    }
+    case CastKind::CK_HLSLVectorToScalarCast: {
+      // The underlying should already be a vector of size 1.
+      assert(hlsl::GetHLSLVecSize(subExpr->getType()) == 1);
+      return doExpr(subExpr);
     }
     case CastKind::CK_FunctionToPointerDecay:
       // Just need to return the function id

+ 1 - 29
tools/clang/test/CodeGenSPIRV/binary-op.arith-assign.mixed.hlsl

@@ -9,41 +9,13 @@ void main() {
     int3 c;
     int t;
 
-// CHECK:      [[s0:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc0:%\d+]] = OpCompositeConstruct %v4float [[s0]] [[s0]] [[s0]] [[s0]]
-// CHECK-NEXT: [[a0:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[add0:%\d+]] = OpFAdd %v4float [[a0]] [[cc0]]
-// CHECK-NEXT: OpStore %a [[add0]]
-    a += s;
-
-// CHECK-NEXT: [[s2:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc2:%\d+]] = OpCompositeConstruct %v4float [[s2]] [[s2]] [[s2]] [[s2]]
-// CHECK-NEXT: [[a2:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[sub0:%\d+]] = OpFSub %v4float [[a2]] [[cc2]]
-// CHECK-NEXT: OpStore %a [[sub0]]
-    a -= s;
-
     // Use OpVectorTimesScalar for floatN * float
-// CHECK-NEXT: [[s4:%\d+]] = OpLoad %float %s
+// CHECK:      [[s4:%\d+]] = OpLoad %float %s
 // CHECK-NEXT: [[a4:%\d+]] = OpLoad %v4float %a
 // CHECK-NEXT: [[mul0:%\d+]] = OpVectorTimesScalar %v4float [[a4]] [[s4]]
 // CHECK-NEXT: OpStore %a [[mul0]]
     a *= s;
 
-// CHECK-NEXT: [[s6:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc6:%\d+]] = OpCompositeConstruct %v4float [[s6]] [[s6]] [[s6]] [[s6]]
-// CHECK-NEXT: [[a6:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[div0:%\d+]] = OpFDiv %v4float [[a6]] [[cc6]]
-// CHECK-NEXT: OpStore %a [[div0]]
-    a /= s;
-
-// CHECK-NEXT: [[s8:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc8:%\d+]] = OpCompositeConstruct %v4float [[s8]] [[s8]] [[s8]] [[s8]]
-// CHECK-NEXT: [[a8:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[mod0:%\d+]] = OpFRem %v4float [[a8]] [[cc8]]
-// CHECK-NEXT: OpStore %a [[mod0]]
-    a %= s;
-
     // Use normal OpCompositeConstruct and OpIMul for intN * int
 // CHECK-NEXT: [[t0:%\d+]] = OpLoad %int %t
 // CHECK-NEXT: [[cc10:%\d+]] = OpCompositeConstruct %v3int [[t0]] [[t0]] [[t0]]

+ 1 - 53
tools/clang/test/CodeGenSPIRV/binary-op.arithmetic.mixed.hlsl

@@ -9,34 +9,8 @@ void main() {
     int3 c, d;
     int t;
 
-// CHECK:      [[a0:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[s0:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc0:%\d+]] = OpCompositeConstruct %v4float [[s0]] [[s0]] [[s0]] [[s0]]
-// CHECK-NEXT: [[add0:%\d+]] = OpFAdd %v4float [[a0]] [[cc0]]
-// CHECK-NEXT: OpStore %b [[add0]]
-    b = a + s;
-// CHECK-NEXT: [[s1:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc1:%\d+]] = OpCompositeConstruct %v4float [[s1]] [[s1]] [[s1]] [[s1]]
-// CHECK-NEXT: [[a1:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[add1:%\d+]] = OpFAdd %v4float [[cc1]] [[a1]]
-// CHECK-NEXT: OpStore %b [[add1]]
-    b = s + a;
-
-// CHECK-NEXT: [[a2:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[s2:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc2:%\d+]] = OpCompositeConstruct %v4float [[s2]] [[s2]] [[s2]] [[s2]]
-// CHECK-NEXT: [[sub0:%\d+]] = OpFSub %v4float [[a2]] [[cc2]]
-// CHECK-NEXT: OpStore %b [[sub0]]
-    b = a - s;
-// CHECK-NEXT: [[s3:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc3:%\d+]] = OpCompositeConstruct %v4float [[s3]] [[s3]] [[s3]] [[s3]]
-// CHECK-NEXT: [[a3:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[sub1:%\d+]] = OpFSub %v4float [[cc3]] [[a3]]
-// CHECK-NEXT: OpStore %b [[sub1]]
-    b = s - a;
-
     // Use OpVectorTimesScalar for floatN * float
-// CHECK-NEXT: [[a4:%\d+]] = OpLoad %v4float %a
+// CHECK:      [[a4:%\d+]] = OpLoad %v4float %a
 // CHECK-NEXT: [[s4:%\d+]] = OpLoad %float %s
 // CHECK-NEXT: [[mul0:%\d+]] = OpVectorTimesScalar %v4float [[a4]] [[s4]]
 // CHECK-NEXT: OpStore %b [[mul0]]
@@ -47,32 +21,6 @@ void main() {
 // CHECK-NEXT: OpStore %b [[mul1]]
     b = s * a;
 
-// CHECK-NEXT: [[a6:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[s6:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc6:%\d+]] = OpCompositeConstruct %v4float [[s6]] [[s6]] [[s6]] [[s6]]
-// CHECK-NEXT: [[div0:%\d+]] = OpFDiv %v4float [[a6]] [[cc6]]
-// CHECK-NEXT: OpStore %b [[div0]]
-    b = a / s;
-// CHECK-NEXT: [[s7:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc7:%\d+]] = OpCompositeConstruct %v4float [[s7]] [[s7]] [[s7]] [[s7]]
-// CHECK-NEXT: [[a7:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[div1:%\d+]] = OpFDiv %v4float [[cc7]] [[a7]]
-// CHECK-NEXT: OpStore %b [[div1]]
-    b = s / a;
-
-// CHECK-NEXT: [[a8:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[s8:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc8:%\d+]] = OpCompositeConstruct %v4float [[s8]] [[s8]] [[s8]] [[s8]]
-// CHECK-NEXT: [[mod0:%\d+]] = OpFRem %v4float [[a8]] [[cc8]]
-// CHECK-NEXT: OpStore %b [[mod0]]
-    b = a % s;
-// CHECK-NEXT: [[s9:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc9:%\d+]] = OpCompositeConstruct %v4float [[s9]] [[s9]] [[s9]] [[s9]]
-// CHECK-NEXT: [[a9:%\d+]] = OpLoad %v4float %a
-// CHECK-NEXT: [[mod1:%\d+]] = OpFRem %v4float [[cc9]] [[a9]]
-// CHECK-NEXT: OpStore %b [[mod1]]
-    b = s % a;
-
     // Use normal OpCompositeConstruct and OpIMul for intN * int
 // CHECK-NEXT: [[c0:%\d+]] = OpLoad %v3int %c
 // CHECK-NEXT: [[t0:%\d+]] = OpLoad %int %t

+ 0 - 42
tools/clang/test/CodeGenSPIRV/binary-op.bitwise-assign.mixed.hlsl

@@ -1,42 +0,0 @@
-// Run: %dxc -T vs_6_0 -E main
-
-// TODO: <scalar> <op>= <vector>. This is allowed in HLSL. It will incur an
-// implicit truncation which only stores the first element into the <scalar>.
-
-void main() {
-// CHECK-LABEL: %bb_entry = OpLabel
-
-    int3 a;
-    int s;
-
-// CHECK:      [[s0:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc0:%\d+]] = OpCompositeConstruct %v3int [[s0]] [[s0]] [[s0]]
-// CHECK-NEXT: [[a0:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[and0:%\d+]] = OpBitwiseAnd %v3int [[a0]] [[cc0]]
-// CHECK-NEXT: OpStore %a [[and0]]
-    a &= s;
-// CHECK-NEXT: [[s1:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc1:%\d+]] = OpCompositeConstruct %v3int [[s1]] [[s1]] [[s1]]
-// CHECK-NEXT: [[a1:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[or0:%\d+]] = OpBitwiseOr %v3int [[a1]] [[cc1]]
-// CHECK-NEXT: OpStore %a [[or0]]
-    a |= s;
-// CHECK-NEXT: [[s2:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc2:%\d+]] = OpCompositeConstruct %v3int [[s2]] [[s2]] [[s2]]
-// CHECK-NEXT: [[a2:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[xor0:%\d+]] = OpBitwiseXor %v3int [[a2]] [[cc2]]
-// CHECK-NEXT: OpStore %a [[xor0]]
-    a ^= s;
-// CHECK-NEXT: [[s3:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc3:%\d+]] = OpCompositeConstruct %v3int [[s3]] [[s3]] [[s3]]
-// CHECK-NEXT: [[a3:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[shl0:%\d+]] = OpShiftLeftLogical %v3int [[a3]] [[cc3]]
-// CHECK-NEXT: OpStore %a [[shl0]]
-    a <<= s;
-// CHECK-NEXT: [[s4:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc4:%\d+]] = OpCompositeConstruct %v3int [[s4]] [[s4]] [[s4]]
-// CHECK-NEXT: [[a4:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[shr0:%\d+]] = OpShiftRightArithmetic %v3int [[a4]] [[cc4]]
-// CHECK-NEXT: OpStore %a [[shr0]]
-    a >>= s;
-}

+ 0 - 73
tools/clang/test/CodeGenSPIRV/binary-op.bitwise.mixed.hlsl

@@ -1,73 +0,0 @@
-// Run: %dxc -T vs_6_0 -E main
-
-void main() {
-// CHECK-LABEL: %bb_entry = OpLabel
-
-    int3 a, b;
-    int s;
-
-// CHECK:      [[a0:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[s0:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc0:%\d+]] = OpCompositeConstruct %v3int [[s0]] [[s0]] [[s0]]
-// CHECK-NEXT: [[b0:%\d+]] = OpBitwiseAnd %v3int [[a0]] [[cc0]]
-// CHECK-NEXT: OpStore %b [[b0]]
-    b = a & s;
-// CHECK-NEXT: [[s1:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc1:%\d+]] = OpCompositeConstruct %v3int [[s1]] [[s1]] [[s1]]
-// CHECK-NEXT: [[a1:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[b1:%\d+]] = OpBitwiseAnd %v3int [[cc1]] [[a1]]
-// CHECK-NEXT: OpStore %b [[b1]]
-    b = s & a;
-
-// CHECK-NEXT: [[a2:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[s2:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc2:%\d+]] = OpCompositeConstruct %v3int [[s2]] [[s2]] [[s2]]
-// CHECK-NEXT: [[b2:%\d+]] = OpBitwiseOr %v3int [[a2]] [[cc2]]
-// CHECK-NEXT: OpStore %b [[b2]]
-    b = a | s;
-// CHECK-NEXT: [[s3:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc3:%\d+]] = OpCompositeConstruct %v3int [[s3]] [[s3]] [[s3]]
-// CHECK-NEXT: [[a3:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[b3:%\d+]] = OpBitwiseOr %v3int [[cc3]] [[a3]]
-// CHECK-NEXT: OpStore %b [[b3]]
-    b = s | a;
-
-// CHECK-NEXT: [[a4:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[s4:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc4:%\d+]] = OpCompositeConstruct %v3int [[s4]] [[s4]] [[s4]]
-// CHECK-NEXT: [[b4:%\d+]] = OpBitwiseXor %v3int [[a4]] [[cc4]]
-// CHECK-NEXT: OpStore %b [[b4]]
-    b = a ^ s;
-// CHECK-NEXT: [[s5:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc5:%\d+]] = OpCompositeConstruct %v3int [[s5]] [[s5]] [[s5]]
-// CHECK-NEXT: [[a5:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[b5:%\d+]] = OpBitwiseXor %v3int [[cc5]] [[a5]]
-// CHECK-NEXT: OpStore %b [[b5]]
-    b = s ^ a;
-
-// CHECK-NEXT: [[a6:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[s6:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc6:%\d+]] = OpCompositeConstruct %v3int [[s6]] [[s6]] [[s6]]
-// CHECK-NEXT: [[b6:%\d+]] = OpShiftLeftLogical %v3int [[a6]] [[cc6]]
-// CHECK-NEXT: OpStore %b [[b6]]
-    b = a << s;
-// CHECK-NEXT: [[s7:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc7:%\d+]] = OpCompositeConstruct %v3int [[s7]] [[s7]] [[s7]]
-// CHECK-NEXT: [[a7:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[b7:%\d+]] = OpShiftLeftLogical %v3int [[cc7]] [[a7]]
-// CHECK-NEXT: OpStore %b [[b7]]
-    b = s << a;
-
-// CHECK-NEXT: [[a8:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[s8:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc8:%\d+]] = OpCompositeConstruct %v3int [[s8]] [[s8]] [[s8]]
-// CHECK-NEXT: [[b8:%\d+]] = OpShiftRightArithmetic %v3int [[a8]] [[cc8]]
-// CHECK-NEXT: OpStore %b [[b8]]
-    b = a >> s;
-// CHECK-NEXT: [[s9:%\d+]] = OpLoad %int %s
-// CHECK-NEXT: [[cc9:%\d+]] = OpCompositeConstruct %v3int [[s9]] [[s9]] [[s9]]
-// CHECK-NEXT: [[a9:%\d+]] = OpLoad %v3int %a
-// CHECK-NEXT: [[b9:%\d+]] = OpShiftRightArithmetic %v3int [[cc9]] [[a9]]
-// CHECK-NEXT: OpStore %b [[b9]]
-    b = s >> a;
-}

+ 0 - 21
tools/clang/test/CodeGenSPIRV/binary-op.comparison.mixed.hlsl

@@ -1,21 +0,0 @@
-// Run: %dxc -T ps_6_0 -E main
-
-void main() {
-// CHECK-LABEL: %bb_entry = OpLabel
-    bool3 r;
-    float3 a;
-    float s;
-
-// CHECK:      [[a0:%\d+]] = OpLoad %v3float %a
-// CHECK-NEXT: [[s0:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc0:%\d+]] = OpCompositeConstruct %v3float [[s0]] [[s0]] [[s0]]
-// CHECK-NEXT: [[lt0:%\d+]] = OpFOrdLessThan %v3bool [[a0]] [[cc0]]
-// CHECK-NEXT: OpStore %r [[lt0]]
-    r = a < s;
-// CHECK-NEXT: [[s1:%\d+]] = OpLoad %float %s
-// CHECK-NEXT: [[cc1:%\d+]] = OpCompositeConstruct %v3float [[s1]] [[s1]] [[s1]]
-// CHECK-NEXT: [[a1:%\d+]] = OpLoad %v3float %a
-// CHECK-NEXT: [[lt1:%\d+]] = OpFOrdLessThan %v3bool [[cc1]] [[a1]]
-// CHECK-NEXT: OpStore %r [[lt1]]
-    r = s < a;
-}

+ 26 - 0
tools/clang/test/CodeGenSPIRV/cast.vector.splat.hlsl

@@ -0,0 +1,26 @@
+// Run: %dxc -T vs_6_0 -E main
+
+void main() {
+// CHECK-LABEL: %bb_entry = OpLabel
+
+    // From constant
+// CHECK:      [[v4f32c:%\d+]] = OpCompositeConstruct %v4float %float_1 %float_1 %float_1 %float_1
+// CHECK-NEXT: OpStore %vf4 [[v4f32c]]
+    float4 vf4 = 1;
+// CHECK-NEXT: [[v3f32c:%\d+]] = OpCompositeConstruct %v3float %float_2 %float_2 %float_2
+// CHECK-NEXT: OpStore %vf3 [[v3f32c]]
+    float3 vf3;
+    vf3 = float1(2);
+
+// CHECK-NEXT: [[si:%\d+]] = OpLoad %int %si
+// CHECK-NEXT: [[vi4:%\d+]] = OpCompositeConstruct %v4int [[si]] [[si]] [[si]] [[si]]
+// CHECK-NEXT: OpStore %vi4 [[vi4]]
+    int si;
+    int4 vi4 = si;
+// CHECK-NEXT: [[si1:%\d+]] = OpLoad %int %si1
+// CHECK-NEXT: [[vi3:%\d+]] = OpCompositeConstruct %v3int [[si1]] [[si1]] [[si1]]
+// CHECK-NEXT: OpStore %vi3 [[vi3]]
+    int1 si1;
+    int3 vi3;
+    vi3 = si1;
+}

+ 60 - 0
tools/clang/test/CodeGenSPIRV/cast.vector.trunc.hlsl

@@ -0,0 +1,60 @@
+// Run: %dxc -T vs_6_0 -E main
+
+// CHECK: [[v4f32c:%\d+]] = OpConstantComposite %v4float %float_1 %float_2 %float_3 %float_4
+// CHECK: [[v3f32c:%\d+]] = OpConstantComposite %v3float %float_5 %float_6 %float_7
+// CHECK: [[v2f32c:%\d+]] = OpConstantComposite %v2float %float_8 %float_9
+
+void main() {
+// CHECK-LABEL: %bb_entry = OpLabel
+
+    // From constant
+// CHECK:      [[c1:%\d+]] = OpCompositeExtract %float [[v4f32c]] 0
+// CHECK-NEXT: [[c2:%\d+]] = OpCompositeExtract %float [[v4f32c]] 1
+// CHECK-NEXT: [[c3:%\d+]] = OpCompositeExtract %float [[v4f32c]] 2
+// CHECK-NEXT: [[vf3:%\d+]] = OpCompositeConstruct %v3float [[c1]] [[c2]] [[c3]]
+// CHECK-NEXT: OpStore %vf3 [[vf3]]
+    float3 vf3 = float4(1, 2, 3, 4);
+// CHECK-NEXT: [[c5:%\d+]] = OpCompositeExtract %float [[v3f32c]] 0
+// CHECK-NEXT: OpStore %vf1 [[c5]]
+    float1 vf1;
+    vf1 = float3(5, 6, 7);
+// CHECK-NEXT: [[c8:%\d+]] = OpCompositeExtract %float [[v2f32c]] 0
+// CHECK-NEXT: OpStore %sfa [[c8]]
+    float sfa = float2(8, 9);
+// CHECK-NEXT: OpStore %sfb %float_10
+    float sfb;
+    sfb = float1(10);
+
+    // From variable
+    int4 vi4;
+// CHECK-NEXT: [[vi4:%\d+]] = OpLoad %v4int %vi4
+// CHECK-NEXT: [[e1:%\d+]] = OpCompositeExtract %int [[vi4]] 0
+// CHECK-NEXT: [[e2:%\d+]] = OpCompositeExtract %int [[vi4]] 1
+// CHECK-NEXT: [[e3:%\d+]] = OpCompositeExtract %int [[vi4]] 2
+// CHECK-NEXT: [[vi3:%\d+]] = OpCompositeConstruct %v3int [[e1]] [[e2]] [[e3]]
+// CHECK-NEXT: OpStore %vi3 [[vi3]]
+    int3 vi3;
+    vi3 = vi4;
+// CHECK-NEXT: [[vi3_1:%\d+]] = OpLoad %v3int %vi3
+// CHECK-NEXT: [[e4:%\d+]] = OpCompositeExtract %int [[vi3_1]] 0
+// CHECK-NEXT: OpStore %vi1 [[e4]]
+    int1 vi1 = vi3;
+// CHECK-NEXT: [[vi3_2:%\d+]] = OpLoad %v3int %vi3
+// CHECK-NEXT: [[e5:%\d+]] = OpCompositeExtract %int [[vi3_2]] 0
+// CHECK-NEXT: OpStore %sia [[e5]]
+    int sia;
+    sia = vi3;
+// CHECK-NEXT: [[vi1:%\d+]] = OpLoad %int %vi1
+// CHECK-NEXT: OpStore %sib [[vi1]]
+    int sib = vi1;
+
+    // Used in expression
+
+// CHECK-NEXT: [[sia:%\d+]] = OpLoad %int %sia
+// CHECK-NEXT: [[cc0:%\d+]] = OpCompositeConstruct %v3int [[sia]] [[sia]] [[sia]]
+// CHECK-NEXT: [[vi3_3:%\d+]] = OpLoad %v3int %vi3
+// CHECK-NEXT: [[add:%\d+]] = OpIAdd %v3int [[cc0]] [[vi3_3]]
+// CHECK-NEXT: [[e6:%\d+]] = OpCompositeExtract %int [[add]] 0
+// CHECK-NEXT: OpStore %sib [[e6]]
+    sib = sia + vi3;
+}

+ 21 - 1
tools/clang/test/CodeGenSPIRV/type.vector.hlsl

@@ -14,8 +14,28 @@ void main() {
 // CHECK-DAG: %_ptr_Function_v4float = OpTypePointer Function %v4float
     float4 d;
 
-// CHECK: %a = OpVariable %_ptr_Function_float Function
+// CHECK-DAG: %int = OpTypeInt 32 1
+// CHECK-DAG: %_ptr_Function_int = OpTypePointer Function %int
+    vector<int, 1> e;
+// CHECK-DAG: %v2uint = OpTypeVector %uint 2
+// CHECK-DAG: %_ptr_Function_v2uint = OpTypePointer Function %v2uint
+    vector<uint, 2> f;
+// CHECK-DAG: %v3bool = OpTypeVector %bool 3
+// CHECK-DAG: %_ptr_Function_v3bool = OpTypePointer Function %v3bool
+    vector<bool, 3> g;
+// CHECK-DAG: %v4int = OpTypeVector %int 4
+// CHECK-DAG: %_ptr_Function_v4int = OpTypePointer Function %v4int
+    vector<int, 4> h;
+
+// CHECK-LABEL: %bb_entry = OpLabel
+
+// CHECK-NEXT: %a = OpVariable %_ptr_Function_float Function
 // CHECK-NEXT: %b = OpVariable %_ptr_Function_v2float Function
 // CHECK-NEXT: %c = OpVariable %_ptr_Function_v3float Function
 // CHECK-NEXT: %d = OpVariable %_ptr_Function_v4float Function
+
+// CHECK-NEXT: %e = OpVariable %_ptr_Function_int Function
+// CHECK-NEXT: %f = OpVariable %_ptr_Function_v2uint Function
+// CHECK-NEXT: %g = OpVariable %_ptr_Function_v3bool Function
+// CHECK-NEXT: %h = OpVariable %_ptr_Function_v4int Function
 }

+ 5 - 9
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -98,9 +98,6 @@ TEST_F(FileTest, BinaryOpScalarBitwise) {
 TEST_F(FileTest, BinaryOpVectorBitwise) {
   runFileTest("binary-op.bitwise.vector.hlsl");
 }
-TEST_F(FileTest, BinaryOpMixedBitwise) {
-  runFileTest("binary-op.bitwise.mixed.hlsl");
-}
 
 // For bitwise assignments
 TEST_F(FileTest, BinaryOpScalarBitwiseAssign) {
@@ -109,9 +106,6 @@ TEST_F(FileTest, BinaryOpScalarBitwiseAssign) {
 TEST_F(FileTest, BinaryOpVectorBitwiseAssign) {
   runFileTest("binary-op.bitwise-assign.vector.hlsl");
 }
-TEST_F(FileTest, BinaryOpMixedBitwiseAssign) {
-  runFileTest("binary-op.bitwise-assign.mixed.hlsl");
-}
 
 // For comparison operators
 TEST_F(FileTest, BinaryOpScalarComparison) {
@@ -120,9 +114,6 @@ TEST_F(FileTest, BinaryOpScalarComparison) {
 TEST_F(FileTest, BinaryOpVectorComparison) {
   runFileTest("binary-op.comparison.vector.hlsl");
 }
-TEST_F(FileTest, BinaryOpMixedComparison) {
-  runFileTest("binary-op.comparison.mixed.hlsl");
-}
 
 // For logical binary operators
 TEST_F(FileTest, BinaryOpLogicalAnd) {
@@ -148,6 +139,11 @@ TEST_F(FileTest, CastExplicit2UInt) { runFileTest("cast.2uint.explicit.hlsl"); }
 TEST_F(FileTest, CastImplicit2FP) { runFileTest("cast.2fp.implicit.hlsl"); }
 TEST_F(FileTest, CastExplicit2FP) { runFileTest("cast.2fp.explicit.hlsl"); }
 
+// For vector splatting and trunction
+
+TEST_F(FileTest, CastTruncateVector) { runFileTest("cast.vector.trunc.hlsl"); }
+TEST_F(FileTest, CastSplatVector) { runFileTest("cast.vector.splat.hlsl"); }
+
 // For if statements
 TEST_F(FileTest, IfStmtPlainAssign) { runFileTest("if-stmt.plain.hlsl"); }
 TEST_F(FileTest, IfStmtNestedIfStmt) { runFileTest("if-stmt.nested.hlsl"); }