Skip to content

Commit 4eca449

Browse files
committed
Add test case for Splat converted to ConstVec
1 parent 02f6743 commit 4eca449

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,10 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
901901
rewriter.eraseOp(op);
902902
return mlir::success();
903903
}
904+
} else if (const auto vecTy = mlir::dyn_cast<cir::VectorType>(op.getType())) {
905+
rewriter.replaceOp(op, lowerCirAttrAsValue(op, op.getValue(), rewriter,
906+
getTypeConverter()));
907+
return mlir::success();
904908
} else {
905909
return op.emitError() << "unsupported constant type " << op.getType();
906910
}

clang/test/CIR/CodeGen/vector-ext.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,3 +1223,66 @@ void foo20() {
12231223
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
12241224
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
12251225
// OGCG: %[[SHUF:.*]] = shufflevector <4 x i32> %[[TMP_A]], <4 x i32> %[[TMP_B]], <4 x i32> <i32 poison, i32 1, i32 poison, i32 1>
1226+
1227+
void foo21() {
1228+
vi4 a = {1, 2, 3, 4};
1229+
vi4 shl = a << 3;
1230+
1231+
uvi4 b = {1u, 2u, 3u, 4u};
1232+
uvi4 shr = b >> 3u;
1233+
}
1234+
1235+
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a", init]
1236+
// CIR: %[[SHL_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shl", init]
1237+
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>, ["b", init]
1238+
// CIR: %[[SHR_RES:.*]] = cir.alloca !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>, ["shr", init]
1239+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
1240+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
1241+
// CIR: %[[CONST_3:.*]] = cir.const #cir.int<3> : !s32i
1242+
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !s32i
1243+
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%[[CONST_1]], %[[CONST_2]], %[[CONST_3]], %[[CONST_4]] :
1244+
// CIR-SAME: !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
1245+
// CIR: cir.store{{.*}} %[[VEC_A_VAL]], %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
1246+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[VEC_A]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
1247+
// CIR: %[[SPLAT_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<3> : !s32i, #cir.int<3> :
1248+
// CIR-SAME: !s32i, #cir.int<3> : !s32i, #cir.int<3> : !s32i]> : !cir.vector<4 x !s32i>
1249+
// CIR: %[[SHL:.*]] = cir.shift(left, %[[TMP_A]] : !cir.vector<4 x !s32i>, %[[SPLAT_VEC]] : !cir.vector<4 x !s32i>) -> !cir.vector<4 x !s32i>
1250+
// CIR: cir.store{{.*}} %[[SHL]], %[[SHL_RES]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
1251+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !u32i
1252+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !u32i
1253+
// CIR: %[[CONST_3:.*]] = cir.const #cir.int<3> : !u32i
1254+
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !u32i
1255+
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%[[CONST_1]], %[[CONST_2]], %[[CONST_3]], %[[CONST_4]] :
1256+
// CIR-SAME: !u32i, !u32i, !u32i, !u32i) : !cir.vector<4 x !u32i>
1257+
// CIR: cir.store{{.*}} %[[VEC_B_VAL]], %[[VEC_B]] : !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>
1258+
// CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[VEC_B]] : !cir.ptr<!cir.vector<4 x !u32i>>, !cir.vector<4 x !u32i>
1259+
// CIR: %[[SPLAT_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<3> : !u32i, #cir.int<3> : !u32i,
1260+
// CIR-SAME: #cir.int<3> : !u32i, #cir.int<3> : !u32i]> : !cir.vector<4 x !u32i>
1261+
// CIR: %[[SHR:.*]] = cir.shift(right, %[[TMP_B]] : !cir.vector<4 x !u32i>, %[[SPLAT_VEC]] : !cir.vector<4 x !u32i>) -> !cir.vector<4 x !u32i>
1262+
// CIR: cir.store{{.*}} %[[SHR]], %[[SHR_RES]] : !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>
1263+
1264+
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16
1265+
// LLVM: %[[SHL_RES:.*]] = alloca <4 x i32>, i64 1, align 16
1266+
// LLVM: %[[VEC_B:.*]] = alloca <4 x i32>, i64 1, align 16
1267+
// LLVM: %[[SHR_RES:.*]] = alloca <4 x i32>, i64 1, align 16
1268+
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_A]], align 16
1269+
// LLVM: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
1270+
// LLVM: %[[SHL:.*]] = shl <4 x i32> %[[TMP_A]], splat (i32 3)
1271+
// LLVM: store <4 x i32> %[[SHL]], ptr %[[SHL_RES]], align 16
1272+
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_B]], align 16
1273+
// LLVM: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
1274+
// LLVM: %[[SHR:.*]] = lshr <4 x i32> %[[TMP_B]], splat (i32 3)
1275+
// LLVM: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16
1276+
1277+
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16
1278+
// OGCG: %[[SHL_RES:.*]] = alloca <4 x i32>, align 16
1279+
// OGCG: %[[VEC_B:.*]] = alloca <4 x i32>, align 16
1280+
// OGCG: %[[SHR_RES:.*]] = alloca <4 x i32>, align 16
1281+
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_A]], align 16
1282+
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
1283+
// OGCG: %[[SHL:.*]] = shl <4 x i32> %[[TMP_A]], splat (i32 3)
1284+
// OGCG: store <4 x i32> %[[SHL]], ptr %[[SHL_RES]], align 16
1285+
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_B]], align 16
1286+
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
1287+
// OGCG: %[[SHR:.*]] = lshr <4 x i32> %[[TMP_B]], splat (i32 3)
1288+
// OGCG: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16

clang/test/CIR/CodeGen/vector.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,3 +1256,66 @@ void foo23() {
12561256
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
12571257
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
12581258
// OGCG: %[[SHUF:.*]] = shufflevector <4 x i32> %[[TMP_A]], <4 x i32> %[[TMP_B]], <4 x i32> <i32 poison, i32 1, i32 poison, i32 1>
1259+
1260+
void foo24() {
1261+
vi4 a = {1, 2, 3, 4};
1262+
vi4 shl = a << 3;
1263+
1264+
uvi4 b = {1u, 2u, 3u, 4u};
1265+
uvi4 shr = b >> 3u;
1266+
}
1267+
1268+
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a", init]
1269+
// CIR: %[[SHL_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shl", init]
1270+
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>, ["b", init]
1271+
// CIR: %[[SHR_RES:.*]] = cir.alloca !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>, ["shr", init]
1272+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
1273+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
1274+
// CIR: %[[CONST_3:.*]] = cir.const #cir.int<3> : !s32i
1275+
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !s32i
1276+
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%[[CONST_1]], %[[CONST_2]], %[[CONST_3]], %[[CONST_4]] :
1277+
// CIR-SAME: !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
1278+
// CIR: cir.store{{.*}} %[[VEC_A_VAL]], %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
1279+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[VEC_A]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
1280+
// CIR: %[[SPLAT_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<3> : !s32i, #cir.int<3> :
1281+
// CIR-SAME: !s32i, #cir.int<3> : !s32i, #cir.int<3> : !s32i]> : !cir.vector<4 x !s32i>
1282+
// CIR: %[[SHL:.*]] = cir.shift(left, %[[TMP_A]] : !cir.vector<4 x !s32i>, %[[SPLAT_VEC]] : !cir.vector<4 x !s32i>) -> !cir.vector<4 x !s32i>
1283+
// CIR: cir.store{{.*}} %[[SHL]], %[[SHL_RES]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
1284+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !u32i
1285+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !u32i
1286+
// CIR: %[[CONST_3:.*]] = cir.const #cir.int<3> : !u32i
1287+
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !u32i
1288+
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%[[CONST_1]], %[[CONST_2]], %[[CONST_3]], %[[CONST_4]] :
1289+
// CIR-SAME: !u32i, !u32i, !u32i, !u32i) : !cir.vector<4 x !u32i>
1290+
// CIR: cir.store{{.*}} %[[VEC_B_VAL]], %[[VEC_B]] : !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>
1291+
// CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[VEC_B]] : !cir.ptr<!cir.vector<4 x !u32i>>, !cir.vector<4 x !u32i>
1292+
// CIR: %[[SPLAT_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<3> : !u32i, #cir.int<3> : !u32i,
1293+
// CIR-SAME: #cir.int<3> : !u32i, #cir.int<3> : !u32i]> : !cir.vector<4 x !u32i>
1294+
// CIR: %[[SHR:.*]] = cir.shift(right, %[[TMP_B]] : !cir.vector<4 x !u32i>, %[[SPLAT_VEC]] : !cir.vector<4 x !u32i>) -> !cir.vector<4 x !u32i>
1295+
// CIR: cir.store{{.*}} %[[SHR]], %[[SHR_RES]] : !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>
1296+
1297+
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16
1298+
// LLVM: %[[SHL_RES:.*]] = alloca <4 x i32>, i64 1, align 16
1299+
// LLVM: %[[VEC_B:.*]] = alloca <4 x i32>, i64 1, align 16
1300+
// LLVM: %[[SHR_RES:.*]] = alloca <4 x i32>, i64 1, align 16
1301+
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_A]], align 16
1302+
// LLVM: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
1303+
// LLVM: %[[SHL:.*]] = shl <4 x i32> %[[TMP_A]], splat (i32 3)
1304+
// LLVM: store <4 x i32> %[[SHL]], ptr %[[SHL_RES]], align 16
1305+
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_B]], align 16
1306+
// LLVM: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
1307+
// LLVM: %[[SHR:.*]] = lshr <4 x i32> %[[TMP_B]], splat (i32 3)
1308+
// LLVM: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16
1309+
1310+
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16
1311+
// OGCG: %[[SHL_RES:.*]] = alloca <4 x i32>, align 16
1312+
// OGCG: %[[VEC_B:.*]] = alloca <4 x i32>, align 16
1313+
// OGCG: %[[SHR_RES:.*]] = alloca <4 x i32>, align 16
1314+
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_A]], align 16
1315+
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
1316+
// OGCG: %[[SHL:.*]] = shl <4 x i32> %[[TMP_A]], splat (i32 3)
1317+
// OGCG: store <4 x i32> %[[SHL]], ptr %[[SHL_RES]], align 16
1318+
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_B]], align 16
1319+
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
1320+
// OGCG: %[[SHR:.*]] = lshr <4 x i32> %[[TMP_B]], splat (i32 3)
1321+
// OGCG: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16

0 commit comments

Comments
 (0)