[HLSL][Matrix] Convert loaded bool matrices to `i1` (#226599)

Fixes #226308.

This PR converts loaded bool matrices to their `i1` representation
before use, like bool vectors do, and updates the affected matrix
codegen tests. 
It also splits matrix tests out of `or.hlsl` into its own `or_mat.hlsl`
file to match the convention of the other matrix intrinsic tests.

Assisted-by: Claude Opus 4.8
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index df16b4f..b1d8c42 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2320,7 +2320,8 @@
   }
 
   llvm::Type *ResTy = ConvertType(Ty);
-  bool HasBoolRep = Ty->hasBooleanRepresentation() || Ty->isExtVectorBoolType();
+  bool HasBoolRep = Ty->hasBooleanRepresentation() ||
+                    Ty->isExtVectorBoolType() || Ty->isConstantMatrixBoolType();
   if (HasBoolRep && CGM.getCodeGenOpts().isConvertingBoolWithCmp0()) {
     return Builder.CreateICmpNE(
         Value, llvm::Constant::getNullValue(Value->getType()), "loadedv");
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 308c45b..c91ed14 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2225,7 +2225,7 @@
     MB.CreateIndexAssumption(RowIdx, NumRows);
 
   Value *FlatMatrix = Visit(E->getBase());
-  llvm::Type *ElemTy = CGF.ConvertTypeForMem(MatrixTy->getElementType());
+  llvm::Type *ElemTy = CGF.ConvertType(MatrixTy->getElementType());
   auto *ResultTy = llvm::FixedVectorType::get(ElemTy, NumColumns);
   Value *RowVec = llvm::PoisonValue::get(ResultTy);
 
@@ -2239,7 +2239,7 @@
     RowVec = Builder.CreateInsertElement(RowVec, Elt, Lane, "matrix_row_ins");
   }
 
-  return CGF.EmitFromMemory(RowVec, E->getType());
+  return RowVec;
 }
 
 Value *ScalarExprEmitter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
diff --git a/clang/test/CodeGenHLSL/BasicFeatures/MatrixSingleSubscriptGetter.hlsl b/clang/test/CodeGenHLSL/BasicFeatures/MatrixSingleSubscriptGetter.hlsl
index 07cad82..a23c280 100644
--- a/clang/test/CodeGenHLSL/BasicFeatures/MatrixSingleSubscriptGetter.hlsl
+++ b/clang/test/CodeGenHLSL/BasicFeatures/MatrixSingleSubscriptGetter.hlsl
@@ -222,17 +222,17 @@
 // CHECK-NEXT:    store i32 [[INDEX]], ptr [[INDEX_ADDR]], align 4
 // CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[INDEX_ADDR]], align 4
 // CHECK-NEXT:    [[TMP2:%.*]] = load <6 x i32>, ptr [[M_ADDR]], align 4
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <6 x i32> [[TMP2]], zeroinitializer
 // CHECK-NEXT:    [[TMP3:%.*]] = add i32 0, [[TMP1]]
-// CHECK-NEXT:    [[MATRIX_ELEM:%.*]] = extractelement <6 x i32> [[TMP2]], i32 [[TMP3]]
-// CHECK-NEXT:    [[MATRIX_ROW_INS:%.*]] = insertelement <3 x i32> poison, i32 [[MATRIX_ELEM]], i32 0
+// CHECK-NEXT:    [[MATRIX_ELEM:%.*]] = extractelement <6 x i1> [[LOADEDV]], i32 [[TMP3]]
+// CHECK-NEXT:    [[MATRIX_ROW_INS:%.*]] = insertelement <3 x i1> poison, i1 [[MATRIX_ELEM]], i32 0
 // CHECK-NEXT:    [[TMP4:%.*]] = add i32 2, [[TMP1]]
-// CHECK-NEXT:    [[MATRIX_ELEM1:%.*]] = extractelement <6 x i32> [[TMP2]], i32 [[TMP4]]
-// CHECK-NEXT:    [[MATRIX_ROW_INS2:%.*]] = insertelement <3 x i32> [[MATRIX_ROW_INS]], i32 [[MATRIX_ELEM1]], i32 1
+// CHECK-NEXT:    [[MATRIX_ELEM1:%.*]] = extractelement <6 x i1> [[LOADEDV]], i32 [[TMP4]]
+// CHECK-NEXT:    [[MATRIX_ROW_INS2:%.*]] = insertelement <3 x i1> [[MATRIX_ROW_INS]], i1 [[MATRIX_ELEM1]], i32 1
 // CHECK-NEXT:    [[TMP5:%.*]] = add i32 4, [[TMP1]]
-// CHECK-NEXT:    [[MATRIX_ELEM3:%.*]] = extractelement <6 x i32> [[TMP2]], i32 [[TMP5]]
-// CHECK-NEXT:    [[MATRIX_ROW_INS4:%.*]] = insertelement <3 x i32> [[MATRIX_ROW_INS2]], i32 [[MATRIX_ELEM3]], i32 2
-// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <3 x i32> [[MATRIX_ROW_INS4]], zeroinitializer
-// CHECK-NEXT:    ret <3 x i1> [[LOADEDV]]
+// CHECK-NEXT:    [[MATRIX_ELEM3:%.*]] = extractelement <6 x i1> [[LOADEDV]], i32 [[TMP5]]
+// CHECK-NEXT:    [[MATRIX_ROW_INS4:%.*]] = insertelement <3 x i1> [[MATRIX_ROW_INS2]], i1 [[MATRIX_ELEM3]], i32 2
+// CHECK-NEXT:    ret <3 x i1> [[MATRIX_ROW_INS4]]
 //
 bool3 getBoolVecMatrixDynamic(bool2x3 M, int index) {
     return M[index];
@@ -246,16 +246,16 @@
 // CHECK-NEXT:    [[TMP0:%.*]] = zext <16 x i1> [[M]] to <16 x i32>
 // CHECK-NEXT:    store <16 x i32> [[TMP0]], ptr [[M_ADDR]], align 4
 // CHECK-NEXT:    [[TMP1:%.*]] = load <16 x i32>, ptr [[M_ADDR]], align 4
-// CHECK-NEXT:    [[MATRIX_ELEM:%.*]] = extractelement <16 x i32> [[TMP1]], i32 0
-// CHECK-NEXT:    [[MATRIX_ROW_INS:%.*]] = insertelement <4 x i32> poison, i32 [[MATRIX_ELEM]], i32 0
-// CHECK-NEXT:    [[MATRIX_ELEM1:%.*]] = extractelement <16 x i32> [[TMP1]], i32 4
-// CHECK-NEXT:    [[MATRIX_ROW_INS2:%.*]] = insertelement <4 x i32> [[MATRIX_ROW_INS]], i32 [[MATRIX_ELEM1]], i32 1
-// CHECK-NEXT:    [[MATRIX_ELEM3:%.*]] = extractelement <16 x i32> [[TMP1]], i32 8
-// CHECK-NEXT:    [[MATRIX_ROW_INS4:%.*]] = insertelement <4 x i32> [[MATRIX_ROW_INS2]], i32 [[MATRIX_ELEM3]], i32 2
-// CHECK-NEXT:    [[MATRIX_ELEM5:%.*]] = extractelement <16 x i32> [[TMP1]], i32 12
-// CHECK-NEXT:    [[MATRIX_ROW_INS6:%.*]] = insertelement <4 x i32> [[MATRIX_ROW_INS4]], i32 [[MATRIX_ELEM5]], i32 3
-// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <4 x i32> [[MATRIX_ROW_INS6]], zeroinitializer
-// CHECK-NEXT:    ret <4 x i1> [[LOADEDV]]
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <16 x i32> [[TMP1]], zeroinitializer
+// CHECK-NEXT:    [[MATRIX_ELEM:%.*]] = extractelement <16 x i1> [[LOADEDV]], i32 0
+// CHECK-NEXT:    [[MATRIX_ROW_INS:%.*]] = insertelement <4 x i1> poison, i1 [[MATRIX_ELEM]], i32 0
+// CHECK-NEXT:    [[MATRIX_ELEM1:%.*]] = extractelement <16 x i1> [[LOADEDV]], i32 4
+// CHECK-NEXT:    [[MATRIX_ROW_INS2:%.*]] = insertelement <4 x i1> [[MATRIX_ROW_INS]], i1 [[MATRIX_ELEM1]], i32 1
+// CHECK-NEXT:    [[MATRIX_ELEM3:%.*]] = extractelement <16 x i1> [[LOADEDV]], i32 8
+// CHECK-NEXT:    [[MATRIX_ROW_INS4:%.*]] = insertelement <4 x i1> [[MATRIX_ROW_INS2]], i1 [[MATRIX_ELEM3]], i32 2
+// CHECK-NEXT:    [[MATRIX_ELEM5:%.*]] = extractelement <16 x i1> [[LOADEDV]], i32 12
+// CHECK-NEXT:    [[MATRIX_ROW_INS6:%.*]] = insertelement <4 x i1> [[MATRIX_ROW_INS4]], i1 [[MATRIX_ELEM5]], i32 3
+// CHECK-NEXT:    ret <4 x i1> [[MATRIX_ROW_INS6]]
 //
 bool4 getBoolVecMatrixConstant(bool4x4 M) {
     return M[0];
@@ -269,10 +269,10 @@
 // CHECK-NEXT:    [[TMP0:%.*]] = zext <3 x i1> [[M]] to <3 x i32>
 // CHECK-NEXT:    store <3 x i32> [[TMP0]], ptr [[M_ADDR]], align 4
 // CHECK-NEXT:    [[TMP1:%.*]] = load <3 x i32>, ptr [[M_ADDR]], align 4
-// CHECK-NEXT:    [[MATRIX_ELEM:%.*]] = extractelement <3 x i32> [[TMP1]], i32 1
-// CHECK-NEXT:    [[MATRIX_ROW_INS:%.*]] = insertelement <1 x i32> poison, i32 [[MATRIX_ELEM]], i32 0
-// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <1 x i32> [[MATRIX_ROW_INS]], zeroinitializer
-// CHECK-NEXT:    [[CAST_VTRUNC:%.*]] = extractelement <1 x i1> [[LOADEDV]], i32 0
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <3 x i32> [[TMP1]], zeroinitializer
+// CHECK-NEXT:    [[MATRIX_ELEM:%.*]] = extractelement <3 x i1> [[LOADEDV]], i32 1
+// CHECK-NEXT:    [[MATRIX_ROW_INS:%.*]] = insertelement <1 x i1> poison, i1 [[MATRIX_ELEM]], i32 0
+// CHECK-NEXT:    [[CAST_VTRUNC:%.*]] = extractelement <1 x i1> [[MATRIX_ROW_INS]], i32 0
 // CHECK-NEXT:    ret i1 [[CAST_VTRUNC]]
 //
 bool getBoolScalarMatrixConstant(bool3x1 M) {
diff --git a/clang/test/CodeGenHLSL/BasicFeatures/MatrixToAndFromVectorConstructors.hlsl b/clang/test/CodeGenHLSL/BasicFeatures/MatrixToAndFromVectorConstructors.hlsl
index b8d47f8..0c163dc 100644
--- a/clang/test/CodeGenHLSL/BasicFeatures/MatrixToAndFromVectorConstructors.hlsl
+++ b/clang/test/CodeGenHLSL/BasicFeatures/MatrixToAndFromVectorConstructors.hlsl
@@ -125,21 +125,27 @@
 // ROW-CHECK-NEXT:    [[TMP0:%.*]] = zext <3 x i1> [[B_ROW]] to <3 x i32>
 // CHECK-NEXT:    store <3 x i32> [[TMP0]], ptr [[B_ADDR]], align 4
 // CHECK-NEXT:    [[TMP1:%.*]] = load <3 x i32>, ptr [[B_ADDR]], align 4
-// COL-CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <3 x i32> [[TMP1]], i32 0
-// ROW-CHECK-NEXT:    [[TMP1_COL:%.*]] = call <3 x i32> @llvm.matrix.transpose.v3i32(<3 x i32> [[TMP1]], i32 3, i32 1)
-// ROW-CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <3 x i32> [[TMP1_COL]], i32 0
-// CHECK-NEXT:    [[VECINIT:%.*]] = insertelement <3 x i32> poison, i32 [[MATRIXEXT]], i32 0
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <3 x i32> [[TMP1]], zeroinitializer
+// COL-CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <3 x i1> [[LOADEDV]], i32 0
+// ROW-CHECK-NEXT:    [[LOADEDV_COL:%.*]] = call <3 x i1> @llvm.matrix.transpose.v3i1(<3 x i1> [[LOADEDV]], i32 3, i32 1)
+// ROW-CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <3 x i1> [[LOADEDV_COL]], i32 0
+// CHECK-NEXT:    [[CONV:%.*]] = zext i1 [[MATRIXEXT]] to i32
+// CHECK-NEXT:    [[VECINIT:%.*]] = insertelement <3 x i32> poison, i32 [[CONV]], i32 0
 // CHECK-NEXT:    [[TMP2:%.*]] = load <3 x i32>, ptr [[B_ADDR]], align 4
-// COL-CHECK-NEXT:    [[MATRIXEXT1:%.*]] = extractelement <3 x i32> [[TMP2]], i32 1
-// ROW-CHECK-NEXT:    [[TMP2_COL:%.*]] = call <3 x i32> @llvm.matrix.transpose.v3i32(<3 x i32> [[TMP2]], i32 3, i32 1)
-// ROW-CHECK-NEXT:    [[MATRIXEXT1:%.*]] = extractelement <3 x i32> [[TMP2_COL]], i32 1
-// CHECK-NEXT:    [[VECINIT2:%.*]] = insertelement <3 x i32> [[VECINIT]], i32 [[MATRIXEXT1]], i32 1
+// CHECK-NEXT:    [[LOADEDV2:%.*]] = icmp ne <3 x i32> [[TMP2]], zeroinitializer
+// COL-CHECK-NEXT:    [[MATRIXEXT2:%.*]] = extractelement <3 x i1> [[LOADEDV2]], i32 1
+// ROW-CHECK-NEXT:    [[LOADEDV2_COL:%.*]] = call <3 x i1> @llvm.matrix.transpose.v3i1(<3 x i1> [[LOADEDV2]], i32 3, i32 1)
+// ROW-CHECK-NEXT:    [[MATRIXEXT2:%.*]] = extractelement <3 x i1> [[LOADEDV2_COL]], i32 1
+// CHECK-NEXT:    [[CONV2:%.*]] = zext i1 [[MATRIXEXT2]] to i32
+// CHECK-NEXT:    [[VECINIT2:%.*]] = insertelement <3 x i32> [[VECINIT]], i32 [[CONV2]], i32 1
 // CHECK-NEXT:    [[TMP3:%.*]] = load <3 x i32>, ptr [[B_ADDR]], align 4
-// COL-CHECK-NEXT:    [[MATRIXEXT3:%.*]] = extractelement <3 x i32> [[TMP3]], i32 2
-// ROW-CHECK-NEXT:    [[TMP3_COL:%.*]] = call <3 x i32> @llvm.matrix.transpose.v3i32(<3 x i32> [[TMP3]], i32 3, i32 1)
-// ROW-CHECK-NEXT:    [[MATRIXEXT3:%.*]] = extractelement <3 x i32> [[TMP3_COL]], i32 2
-// CHECK-NEXT:    [[VECINIT4:%.*]] = insertelement <3 x i32> [[VECINIT2]], i32 [[MATRIXEXT3]], i32 2
-// CHECK-NEXT:    ret <3 x i32> [[VECINIT4]]
+// CHECK-NEXT:    [[LOADEDV3:%.*]] = icmp ne <3 x i32> [[TMP3]], zeroinitializer
+// COL-CHECK-NEXT:    [[MATRIXEXT3:%.*]] = extractelement <3 x i1> [[LOADEDV3]], i32 2
+// ROW-CHECK-NEXT:    [[LOADEDV3_COL:%.*]] = call <3 x i1> @llvm.matrix.transpose.v3i1(<3 x i1> [[LOADEDV3]], i32 3, i32 1)
+// ROW-CHECK-NEXT:    [[MATRIXEXT3:%.*]] = extractelement <3 x i1> [[LOADEDV3_COL]], i32 2
+// CHECK-NEXT:    [[CONV3:%.*]] = zext i1 [[MATRIXEXT3]] to i32
+// CHECK-NEXT:    [[VECINIT3:%.*]] = insertelement <3 x i32> [[VECINIT2]], i32 [[CONV3]], i32 2
+// CHECK-NEXT:    ret <3 x i32> [[VECINIT3]]
 //
 int3 fn3(bool1x3 b) {
     return b;
diff --git a/clang/test/CodeGenHLSL/BasicFeatures/VectorElementwiseCast.hlsl b/clang/test/CodeGenHLSL/BasicFeatures/VectorElementwiseCast.hlsl
index 5420289..99d0bcd 100644
--- a/clang/test/CodeGenHLSL/BasicFeatures/VectorElementwiseCast.hlsl
+++ b/clang/test/CodeGenHLSL/BasicFeatures/VectorElementwiseCast.hlsl
@@ -198,10 +198,12 @@
 // ROW-CHECK-NEXT:    [[TMP0:%.*]] = zext <2 x i1> [[M_ROW]] to <2 x i32>
 // CHECK-NEXT:    store <2 x i32> [[TMP0]], ptr [[M_ADDR]], align 4
 // CHECK-NEXT:    [[TMP1:%.*]] = load <2 x i32>, ptr [[M_ADDR]], align 4
-// COL-CHECK-NEXT:    store <2 x i32> [[TMP1]], ptr [[HLSL_EWCAST_SRC]], align 4
-// ROW-CHECK-NEXT:    [[TMP1_COL:%.*]] = call <2 x i32> @llvm.matrix.transpose.v2i32(<2 x i32> [[TMP1]], i32 2, i32 1)
-// ROW-CHECK-NEXT:    [[TMP1_ROW:%.*]] = call <2 x i32> @llvm.matrix.transpose.v2i32(<2 x i32> [[TMP1_COL]], i32 1, i32 2)
-// ROW-CHECK-NEXT:    store <2 x i32> [[TMP1_ROW]], ptr [[HLSL_EWCAST_SRC]], align 4
+// CHECK-NEXT:    [[M_LOADEDV:%.*]] = icmp ne <2 x i32> [[TMP1]], zeroinitializer
+// COL-CHECK-NEXT:    [[M_EXT:%.*]] = zext <2 x i1> [[M_LOADEDV]] to <2 x i32>
+// ROW-CHECK-NEXT:    [[M_LOADEDV_COL:%.*]] = call <2 x i1> @llvm.matrix.transpose.v2i1(<2 x i1> [[M_LOADEDV]], i32 2, i32 1)
+// ROW-CHECK-NEXT:    [[M_LOADEDV_ROW:%.*]] = call <2 x i1> @llvm.matrix.transpose.v2i1(<2 x i1> [[M_LOADEDV_COL]], i32 1, i32 2)
+// ROW-CHECK-NEXT:    [[M_EXT:%.*]] = zext <2 x i1> [[M_LOADEDV_ROW]] to <2 x i32>
+// CHECK-NEXT:    store <2 x i32> [[M_EXT]], ptr [[HLSL_EWCAST_SRC]], align 4
 // CHECK-NEXT:    [[MATRIX_GEP:%.*]] = getelementptr inbounds <2 x i32>, ptr [[HLSL_EWCAST_SRC]], i32 0
 // CHECK-NEXT:    [[TMP3:%.*]] = load <2 x i32>, ptr [[MATRIX_GEP]], align 4
 // CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <2 x i32> [[TMP3]], i32 0
diff --git a/clang/test/CodeGenHLSL/BoolMatrix.hlsl b/clang/test/CodeGenHLSL/BoolMatrix.hlsl
index eeb2fa8..65e4a0b 100644
--- a/clang/test/CodeGenHLSL/BoolMatrix.hlsl
+++ b/clang/test/CodeGenHLSL/BoolMatrix.hlsl
@@ -11,14 +11,12 @@
 // CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
-// CHECK-NEXT:    [[RETVAL:%.*]] = alloca i1, align 4
 // CHECK-NEXT:    [[B:%.*]] = alloca [2 x <2 x i32>], align 4
 // CHECK-NEXT:    store <4 x i32> splat (i32 1), ptr [[B]], align 4
 // CHECK-NEXT:    [[TMP0:%.*]] = load <4 x i32>, ptr [[B]], align 4
-// CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <4 x i32> [[TMP0]], i32 0
-// CHECK-NEXT:    store i32 [[MATRIXEXT]], ptr [[RETVAL]], align 4
-// CHECK-NEXT:    [[TMP1:%.*]] = load i1, ptr [[RETVAL]], align 4
-// CHECK-NEXT:    ret i1 [[TMP1]]
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <4 x i32> [[TMP0]], zeroinitializer
+// CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <4 x i1> [[LOADEDV]], i32 0
+// CHECK-NEXT:    ret i1 [[MATRIXEXT]]
 //
 bool fn1() {
   bool2x2 B = {true,true,true,true};
@@ -29,7 +27,6 @@
 // CHECK-SAME: i1 noundef [[V:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
-// CHECK-NEXT:    [[RETVAL:%.*]] = alloca <4 x i1>, align 4
 // CHECK-NEXT:    [[V_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:    [[A:%.*]] = alloca [2 x <2 x i32>], align 4
 // CHECK-NEXT:    [[STOREDV:%.*]] = zext i1 [[V]] to i32
@@ -45,9 +42,8 @@
 // CHECK-NEXT:    [[TMP2:%.*]] = zext <4 x i1> [[VECINIT4]] to <4 x i32>
 // CHECK-NEXT:    store <4 x i32> [[TMP2]], ptr [[A]], align 4
 // CHECK-NEXT:    [[TMP3:%.*]] = load <4 x i32>, ptr [[A]], align 4
-// CHECK-NEXT:    store <4 x i32> [[TMP3]], ptr [[RETVAL]], align 4
-// CHECK-NEXT:    [[TMP4:%.*]] = load <4 x i1>, ptr [[RETVAL]], align 4
-// CHECK-NEXT:    ret <4 x i1> [[TMP4]]
+// CHECK-NEXT:    [[LOADEDV5:%.*]] = icmp ne <4 x i32> [[TMP3]], zeroinitializer
+// CHECK-NEXT:    ret <4 x i1> [[LOADEDV5]]
 //
 bool2x2 fn2(bool V) {
   bool2x2 A = {V, true, V, false};
@@ -58,15 +54,13 @@
 // CHECK-SAME: ) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
-// CHECK-NEXT:    [[RETVAL:%.*]] = alloca i1, align 4
 // CHECK-NEXT:    [[S:%.*]] = alloca [[STRUCT_S:%.*]], align 1
 // CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr align 1 [[S]], ptr align 1 @__const._Z3fn3v.s, i32 20, i1 false)
 // CHECK-NEXT:    [[BM:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 0
 // CHECK-NEXT:    [[TMP0:%.*]] = load <4 x i32>, ptr [[BM]], align 1
-// CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <4 x i32> [[TMP0]], i32 0
-// CHECK-NEXT:    store i32 [[MATRIXEXT]], ptr [[RETVAL]], align 4
-// CHECK-NEXT:    [[TMP1:%.*]] = load i1, ptr [[RETVAL]], align 4
-// CHECK-NEXT:    ret i1 [[TMP1]]
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <4 x i32> [[TMP0]], zeroinitializer
+// CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <4 x i1> [[LOADEDV]], i32 0
+// CHECK-NEXT:    ret i1 [[MATRIXEXT]]
 //
 bool fn3() {
   S s = {{true,true,false,false}, 1.0};
@@ -77,15 +71,13 @@
 // CHECK-SAME: ) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
-// CHECK-NEXT:    [[RETVAL:%.*]] = alloca i1, align 4
 // CHECK-NEXT:    [[ARR:%.*]] = alloca [2 x [2 x <2 x i32>]], align 4
 // CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[ARR]], ptr align 4 @constinit, i32 32, i1 false)
 // CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [2 x [2 x <2 x i32>]], ptr [[ARR]], i32 0, i32 0
 // CHECK-NEXT:    [[TMP0:%.*]] = load <4 x i32>, ptr [[ARRAYIDX]], align 4
-// CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <4 x i32> [[TMP0]], i32 1
-// CHECK-NEXT:    store i32 [[MATRIXEXT]], ptr [[RETVAL]], align 4
-// CHECK-NEXT:    [[TMP1:%.*]] = load i1, ptr [[RETVAL]], align 4
-// CHECK-NEXT:    ret i1 [[TMP1]]
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <4 x i32> [[TMP0]], zeroinitializer
+// CHECK-NEXT:    [[MATRIXEXT:%.*]] = extractelement <4 x i1> [[LOADEDV]], i32 1
+// CHECK-NEXT:    ret i1 [[MATRIXEXT]]
 //
 bool fn4() {
   bool2x2 Arr[2] = {{true,true,true,true}, {false,false,false,false}};
@@ -149,14 +141,12 @@
 // CHECK-SAME: <16 x i1> noundef [[M:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    %[[#C_ENTRY:]] = call token @llvm.experimental.convergence.entry()
-// CHECK-NEXT:    [[RETVAL:%.*]] = alloca <16 x i1>, align 4
 // CHECK-NEXT:    [[M_ADDR:%.*]] = alloca [4 x <4 x i32>], align 4
 // CHECK-NEXT:    [[TMP0:%.*]] = zext <16 x i1> [[M]] to <16 x i32>
 // CHECK-NEXT:    store <16 x i32> [[TMP0]], ptr [[M_ADDR]], align 4
 // CHECK-NEXT:    [[TMP1:%.*]] = load <16 x i32>, ptr [[M_ADDR]], align 4
-// CHECK-NEXT:    store <16 x i32> [[TMP1]], ptr [[RETVAL]], align 4
-// CHECK-NEXT:    [[TMP2:%.*]] = load <16 x i1>, ptr [[RETVAL]], align 4
-// CHECK-NEXT:    ret <16 x i1> [[TMP2]]
+// CHECK-NEXT:    [[LOADEDV:%.*]] = icmp ne <16 x i32> [[TMP1]], zeroinitializer
+// CHECK-NEXT:    ret <16 x i1> [[LOADEDV]]
 //
 bool4x4 fn8(bool4x4 m) {
   return m;
diff --git a/clang/test/CodeGenHLSL/builtins/and_mat.hlsl b/clang/test/CodeGenHLSL/builtins/and_mat.hlsl
index c070dd9..66c87c5 100644
--- a/clang/test/CodeGenHLSL/builtins/and_mat.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/and_mat.hlsl
@@ -5,8 +5,8 @@
 // CHECK-LABEL: define hidden noundef <2 x i1> @_Z16test_and_bool1x2u11matrix_typeILm1ELm2EbES_(
 // CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <2 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <2 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <2 x i1> [[HLSL_AND]]
 bool1x2 test_and_bool1x2(bool1x2 x, bool1x2 y)
 {
     return and(x, y);
@@ -15,8 +15,8 @@
 // CHECK-LABEL: define hidden noundef <3 x i1> @_Z16test_and_bool1x3u11matrix_typeILm1ELm3EbES_(
 // CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <3 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <3 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <3 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <3 x i1> [[HLSL_AND]]
 bool1x3 test_and_bool1x3(bool1x3 x, bool1x3 y)
 {
     return and(x, y);
@@ -25,8 +25,8 @@
 // CHECK-LABEL: define hidden noundef <4 x i1> @_Z16test_and_bool1x4u11matrix_typeILm1ELm4EbES_(
 // CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <4 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <4 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <4 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <4 x i1> [[HLSL_AND]]
 bool1x4 test_and_bool1x4(bool1x4 x, bool1x4 y)
 {
     return and(x, y);
@@ -35,8 +35,8 @@
 // CHECK-LABEL: define hidden noundef <2 x i1> @_Z16test_and_bool2x1u11matrix_typeILm2ELm1EbES_(
 // CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <2 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <2 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <2 x i1> [[HLSL_AND]]
 bool2x1 test_and_bool2x1(bool2x1 x, bool2x1 y)
 {
     return and(x, y);
@@ -46,8 +46,8 @@
 // CHECK-LABEL: define hidden noundef <4 x i1> @_Z16test_and_bool2x2u11matrix_typeILm2ELm2EbES_(
 // CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <4 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <4 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <4 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <4 x i1> [[HLSL_AND]]
 bool2x2 test_and_bool2x2(bool2x2 x, bool2x2 y)
 {
     return and(x, y);
@@ -56,8 +56,8 @@
 // CHECK-LABEL: define hidden noundef <6 x i1> @_Z16test_and_bool2x3u11matrix_typeILm2ELm3EbES_(
 // CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <6 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <6 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <6 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <6 x i1> [[HLSL_AND]]
 bool2x3 test_and_bool2x3(bool2x3 x, bool2x3 y)
 {
     return and(x, y);
@@ -66,8 +66,8 @@
 // CHECK-LABEL: define hidden noundef <8 x i1> @_Z16test_and_bool2x4u11matrix_typeILm2ELm4EbES_(
 // CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <8 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <8 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <8 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <8 x i1> [[HLSL_AND]]
 bool2x4 test_and_bool2x4(bool2x4 x, bool2x4 y)
 {
     return and(x, y);
@@ -76,8 +76,8 @@
 // CHECK-LABEL: define hidden noundef <3 x i1> @_Z16test_and_bool3x1u11matrix_typeILm3ELm1EbES_(
 // CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <3 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <3 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <3 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <3 x i1> [[HLSL_AND]]
 bool3x1 test_and_bool3x1(bool3x1 x, bool3x1 y)
 {
     return and(x, y);
@@ -86,8 +86,8 @@
 // CHECK-LABEL: define hidden noundef <6 x i1> @_Z16test_and_bool3x2u11matrix_typeILm3ELm2EbES_(
 // CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <6 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <6 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <6 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <6 x i1> [[HLSL_AND]]
 bool3x2 test_and_bool3x2(bool3x2 x, bool3x2 y)
 {
     return and(x, y);
@@ -97,8 +97,8 @@
 // CHECK-LABEL: define hidden noundef <9 x i1> @_Z16test_and_bool3x3u11matrix_typeILm3ELm3EbES_(
 // CHECK-SAME: <9 x i1> noundef [[X:%.*]], <9 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <9 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <9 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <9 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <9 x i1> [[HLSL_AND]]
 bool3x3 test_and_bool3x3(bool3x3 x, bool3x3 y)
 {
     return and(x, y);
@@ -107,8 +107,8 @@
 // CHECK-LABEL: define hidden noundef <12 x i1> @_Z16test_and_bool3x4u11matrix_typeILm3ELm4EbES_(
 // CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <12 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <12 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <12 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <12 x i1> [[HLSL_AND]]
 bool3x4 test_and_bool3x4(bool3x4 x, bool3x4 y)
 {
     return and(x, y);
@@ -117,8 +117,8 @@
 // CHECK-LABEL: define hidden noundef <4 x i1> @_Z16test_and_bool4x1u11matrix_typeILm4ELm1EbES_(
 // CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <4 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <4 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <4 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <4 x i1> [[HLSL_AND]]
 bool4x1 test_and_bool4x1(bool4x1 x, bool4x1 y)
 {
     return and(x, y);
@@ -127,8 +127,8 @@
 // CHECK-LABEL: define hidden noundef <8 x i1> @_Z16test_and_bool4x2u11matrix_typeILm4ELm2EbES_(
 // CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <8 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <8 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <8 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <8 x i1> [[HLSL_AND]]
 bool4x2 test_and_bool4x2(bool4x2 x, bool4x2 y)
 {
     return and(x, y);
@@ -137,8 +137,8 @@
 // CHECK-LABEL: define hidden noundef <12 x i1> @_Z16test_and_bool4x3u11matrix_typeILm4ELm3EbES_(
 // CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <12 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <12 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <12 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <12 x i1> [[HLSL_AND]]
 bool4x3 test_and_bool4x3(bool4x3 x, bool4x3 y)
 {
     return and(x, y);
@@ -147,8 +147,8 @@
 // CHECK-LABEL: define hidden noundef <16 x i1> @_Z16test_and_bool4x4u11matrix_typeILm4ELm4EbES_(
 // CHECK-SAME: <16 x i1> noundef [[X:%.*]], <16 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_AND:%.*]] = and <16 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <16 x i1> [[HLSL_AND_CAST:%.*]]
+// CHECK:         [[HLSL_AND:%.*]] = and <16 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <16 x i1> [[HLSL_AND]]
 bool4x4 test_and_bool4x4(bool4x4 x, bool4x4 y)
 {
     return and(x, y);
diff --git a/clang/test/CodeGenHLSL/builtins/or.hlsl b/clang/test/CodeGenHLSL/builtins/or.hlsl
index cf07d2f..429d68c 100644
--- a/clang/test/CodeGenHLSL/builtins/or.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/or.hlsl
@@ -77,155 +77,3 @@
 {
     return or(x, y);
 }
-
-// CHECK-LABEL: define hidden noundef <2 x i1> @_Z15test_or_bool1x2u11matrix_typeILm1ELm2EbES_(
-// CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <2 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <2 x i1> [[HLSL_OR_CAST:%.*]]
-bool1x2 test_or_bool1x2(bool1x2 x, bool1x2 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <3 x i1> @_Z15test_or_bool1x3u11matrix_typeILm1ELm3EbES_(
-// CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <3 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <3 x i1> [[HLSL_OR_CAST:%.*]]
-bool1x3 test_or_bool1x3(bool1x3 x, bool1x3 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <4 x i1> @_Z15test_or_bool1x4u11matrix_typeILm1ELm4EbES_(
-// CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <4 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <4 x i1> [[HLSL_OR_CAST:%.*]]
-bool1x4 test_or_bool1x4(bool1x4 x, bool1x4 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <2 x i1> @_Z15test_or_bool2x1u11matrix_typeILm2ELm1EbES_(
-// CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <2 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <2 x i1> [[HLSL_OR_CAST:%.*]]
-bool2x1 test_or_bool2x1(bool2x1 x, bool2x1 y)
-{
-    return or(x, y);
-}
-
-
-// CHECK-LABEL: define hidden noundef <4 x i1> @_Z15test_or_bool2x2u11matrix_typeILm2ELm2EbES_(
-// CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <4 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <4 x i1> [[HLSL_OR_CAST:%.*]]
-bool2x2 test_or_bool2x2(bool2x2 x, bool2x2 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <6 x i1> @_Z15test_or_bool2x3u11matrix_typeILm2ELm3EbES_(
-// CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <6 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <6 x i1> [[HLSL_OR_CAST:%.*]]
-bool2x3 test_or_bool2x3(bool2x3 x, bool2x3 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <8 x i1> @_Z15test_or_bool2x4u11matrix_typeILm2ELm4EbES_(
-// CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <8 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <8 x i1> [[HLSL_OR_CAST:%.*]]
-bool2x4 test_or_bool2x4(bool2x4 x, bool2x4 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <3 x i1> @_Z15test_or_bool3x1u11matrix_typeILm3ELm1EbES_(
-// CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <3 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <3 x i1> [[HLSL_OR_CAST:%.*]]
-bool3x1 test_or_bool3x1(bool3x1 x, bool3x1 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <6 x i1> @_Z15test_or_bool3x2u11matrix_typeILm3ELm2EbES_(
-// CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <6 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <6 x i1> [[HLSL_OR_CAST:%.*]]
-bool3x2 test_or_bool3x2(bool3x2 x, bool3x2 y)
-{
-    return or(x, y);
-}
-
-
-// CHECK-LABEL: define hidden noundef <9 x i1> @_Z15test_or_bool3x3u11matrix_typeILm3ELm3EbES_(
-// CHECK-SAME: <9 x i1> noundef [[X:%.*]], <9 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <9 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <9 x i1> [[HLSL_OR_CAST:%.*]]
-bool3x3 test_or_bool3x3(bool3x3 x, bool3x3 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <12 x i1> @_Z15test_or_bool3x4u11matrix_typeILm3ELm4EbES_(
-// CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <12 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <12 x i1> [[HLSL_OR_CAST:%.*]]
-bool3x4 test_or_bool3x4(bool3x4 x, bool3x4 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <4 x i1> @_Z15test_or_bool4x1u11matrix_typeILm4ELm1EbES_(
-// CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <4 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <4 x i1> [[HLSL_OR_CAST:%.*]]
-bool4x1 test_or_bool4x1(bool4x1 x, bool4x1 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <8 x i1> @_Z15test_or_bool4x2u11matrix_typeILm4ELm2EbES_(
-// CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <8 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <8 x i1> [[HLSL_OR_CAST:%.*]]
-bool4x2 test_or_bool4x2(bool4x2 x, bool4x2 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <12 x i1> @_Z15test_or_bool4x3u11matrix_typeILm4ELm3EbES_(
-// CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <12 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <12 x i1> [[HLSL_OR_CAST:%.*]]
-bool4x3 test_or_bool4x3(bool4x3 x, bool4x3 y)
-{
-    return or(x, y);
-}
-
-// CHECK-LABEL: define hidden noundef <16 x i1> @_Z15test_or_bool4x4u11matrix_typeILm4ELm4EbES_(
-// CHECK-SAME: <16 x i1> noundef [[X:%.*]], <16 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
-// CHECK-NEXT:  entry:
-// CHECK:         [[HLSL_OR:%.*]] = or <16 x i32> [[A:%.*]], [[B:%.*]]
-// CHECK:         ret <16 x i1> [[HLSL_OR_CAST:%.*]]
-bool4x4 test_or_bool4x4(bool4x4 x, bool4x4 y)
-{
-    return or(x, y);
-}
diff --git a/clang/test/CodeGenHLSL/builtins/or_mat.hlsl b/clang/test/CodeGenHLSL/builtins/or_mat.hlsl
new file mode 100644
index 0000000..2898ff8
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/or_mat.hlsl
@@ -0,0 +1,155 @@
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// CHECK-LABEL: define hidden noundef <2 x i1> @_Z15test_or_bool1x2u11matrix_typeILm1ELm2EbES_(
+// CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <2 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <2 x i1> [[HLSL_OR]]
+bool1x2 test_or_bool1x2(bool1x2 x, bool1x2 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <3 x i1> @_Z15test_or_bool1x3u11matrix_typeILm1ELm3EbES_(
+// CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <3 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <3 x i1> [[HLSL_OR]]
+bool1x3 test_or_bool1x3(bool1x3 x, bool1x3 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <4 x i1> @_Z15test_or_bool1x4u11matrix_typeILm1ELm4EbES_(
+// CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <4 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <4 x i1> [[HLSL_OR]]
+bool1x4 test_or_bool1x4(bool1x4 x, bool1x4 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <2 x i1> @_Z15test_or_bool2x1u11matrix_typeILm2ELm1EbES_(
+// CHECK-SAME: <2 x i1> noundef [[X:%.*]], <2 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <2 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <2 x i1> [[HLSL_OR]]
+bool2x1 test_or_bool2x1(bool2x1 x, bool2x1 y)
+{
+    return or(x, y);
+}
+
+
+// CHECK-LABEL: define hidden noundef <4 x i1> @_Z15test_or_bool2x2u11matrix_typeILm2ELm2EbES_(
+// CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <4 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <4 x i1> [[HLSL_OR]]
+bool2x2 test_or_bool2x2(bool2x2 x, bool2x2 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <6 x i1> @_Z15test_or_bool2x3u11matrix_typeILm2ELm3EbES_(
+// CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <6 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <6 x i1> [[HLSL_OR]]
+bool2x3 test_or_bool2x3(bool2x3 x, bool2x3 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <8 x i1> @_Z15test_or_bool2x4u11matrix_typeILm2ELm4EbES_(
+// CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <8 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <8 x i1> [[HLSL_OR]]
+bool2x4 test_or_bool2x4(bool2x4 x, bool2x4 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <3 x i1> @_Z15test_or_bool3x1u11matrix_typeILm3ELm1EbES_(
+// CHECK-SAME: <3 x i1> noundef [[X:%.*]], <3 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <3 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <3 x i1> [[HLSL_OR]]
+bool3x1 test_or_bool3x1(bool3x1 x, bool3x1 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <6 x i1> @_Z15test_or_bool3x2u11matrix_typeILm3ELm2EbES_(
+// CHECK-SAME: <6 x i1> noundef [[X:%.*]], <6 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <6 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <6 x i1> [[HLSL_OR]]
+bool3x2 test_or_bool3x2(bool3x2 x, bool3x2 y)
+{
+    return or(x, y);
+}
+
+
+// CHECK-LABEL: define hidden noundef <9 x i1> @_Z15test_or_bool3x3u11matrix_typeILm3ELm3EbES_(
+// CHECK-SAME: <9 x i1> noundef [[X:%.*]], <9 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <9 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <9 x i1> [[HLSL_OR]]
+bool3x3 test_or_bool3x3(bool3x3 x, bool3x3 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <12 x i1> @_Z15test_or_bool3x4u11matrix_typeILm3ELm4EbES_(
+// CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <12 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <12 x i1> [[HLSL_OR]]
+bool3x4 test_or_bool3x4(bool3x4 x, bool3x4 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <4 x i1> @_Z15test_or_bool4x1u11matrix_typeILm4ELm1EbES_(
+// CHECK-SAME: <4 x i1> noundef [[X:%.*]], <4 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <4 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <4 x i1> [[HLSL_OR]]
+bool4x1 test_or_bool4x1(bool4x1 x, bool4x1 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <8 x i1> @_Z15test_or_bool4x2u11matrix_typeILm4ELm2EbES_(
+// CHECK-SAME: <8 x i1> noundef [[X:%.*]], <8 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <8 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <8 x i1> [[HLSL_OR]]
+bool4x2 test_or_bool4x2(bool4x2 x, bool4x2 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <12 x i1> @_Z15test_or_bool4x3u11matrix_typeILm4ELm3EbES_(
+// CHECK-SAME: <12 x i1> noundef [[X:%.*]], <12 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <12 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <12 x i1> [[HLSL_OR]]
+bool4x3 test_or_bool4x3(bool4x3 x, bool4x3 y)
+{
+    return or(x, y);
+}
+
+// CHECK-LABEL: define hidden noundef <16 x i1> @_Z15test_or_bool4x4u11matrix_typeILm4ELm4EbES_(
+// CHECK-SAME: <16 x i1> noundef [[X:%.*]], <16 x i1> noundef [[Y:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK:         [[HLSL_OR:%.*]] = or <16 x i1> [[A:%.*]], [[B:%.*]]
+// CHECK:         ret <16 x i1> [[HLSL_OR]]
+bool4x4 test_or_bool4x4(bool4x4 x, bool4x4 y)
+{
+    return or(x, y);
+}
diff --git a/clang/test/CodeGenHLSL/builtins/transpose.hlsl b/clang/test/CodeGenHLSL/builtins/transpose.hlsl
index 09fe32e..a3d7811 100644
--- a/clang/test/CodeGenHLSL/builtins/transpose.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/transpose.hlsl
@@ -9,7 +9,8 @@
 // CHECK:       [[A_EXT:%.*]] = zext <6 x i1> %{{.*}} to <6 x i32>
 // CHECK:       store <6 x i32> [[A_EXT]], ptr [[A_ADDR]], align 4
 // CHECK:       [[A:%.*]] = load <6 x i32>, ptr [[A_ADDR]], align 4
-// COLMAJOR:    [[TRANS:%.*]] = call <6 x i32> @llvm.matrix.transpose.v6i32(<6 x i32> [[A]], i32 2, i32 3)
+// CHECK:       [[LOADEDV:%.*]] = icmp ne <6 x i32> [[A]], zeroinitializer
+// COLMAJOR:    [[TRANS:%.*]] = call <6 x i1> @llvm.matrix.transpose.v6i1(<6 x i1> [[LOADEDV]], i32 2, i32 3)
 // ROWMAJOR-NOT: call {{.*}} @llvm.matrix.transpose
 bool3x2 test_transpose_bool2x3(bool2x3 a) {
   return transpose(a);