Skip to content

Commit 05ef531

Browse files
committed
[CIR] Allow use different Int types together in Vec Shift Op
1 parent a9b2998 commit 05ef531

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,12 +1427,12 @@ OpFoldResult cir::SelectOp::fold(FoldAdaptor adaptor) {
14271427
//===----------------------------------------------------------------------===//
14281428
LogicalResult cir::ShiftOp::verify() {
14291429
mlir::Operation *op = getOperation();
1430-
mlir::Type resType = getResult().getType();
14311430
const bool isOp0Vec = mlir::isa<cir::VectorType>(op->getOperand(0).getType());
14321431
const bool isOp1Vec = mlir::isa<cir::VectorType>(op->getOperand(1).getType());
14331432
if (isOp0Vec != isOp1Vec)
14341433
return emitOpError() << "input types cannot be one vector and one scalar";
1435-
if (isOp1Vec && op->getOperand(1).getType() != resType) {
1434+
1435+
if (isOp1Vec && !mlir::isa<cir::VectorType>(getResult().getType())) {
14361436
return emitOpError() << "shift amount must have the type of the result "
14371437
<< "if it is vector shift";
14381438
}

clang/test/CIR/CodeGen/vector.cpp

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,9 @@ void foo9() {
396396
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["b", init]
397397
// CIR: %[[SHL_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shl", init]
398398
// CIR: %[[SHR_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shr", init]
399-
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
400-
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
401-
// CIR: %[[CONST_3:.*]] = cir.const #cir.int<3> : !s32i
402-
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !s32i
403-
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%[[CONST_1]], %[[CONST_2]], %[[CONST_3]], %[[CONST_4]] :
404-
// CIR-SAME: !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
399+
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
405400
// CIR: cir.store{{.*}} %[[VEC_A_VAL]], %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
406-
// CIR: %[[CONST_5:.*]] = cir.const #cir.int<5> : !s32i
407-
// CIR: %[[CONST_6:.*]] = cir.const #cir.int<6> : !s32i
408-
// CIR: %[[CONST_7:.*]] = cir.const #cir.int<7> : !s32i
409-
// CIR: %[[CONST_8:.*]] = cir.const #cir.int<8> : !s32i
410-
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%[[CONST_5]], %[[CONST_6]], %[[CONST_7]], %[[CONST_8]] :
411-
// CIR-SAME: !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
401+
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
412402
// CIR: cir.store{{.*}} %[[VEC_B_VAL]], %[[VEC_B]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
413403
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[VEC_A]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
414404
// CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[VEC_B]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
@@ -449,6 +439,61 @@ void foo9() {
449439
// OGCG: %[[SHR:.*]] = ashr <4 x i32> %[[TMP_A]], %[[TMP_B]]
450440
// OGCG: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16
451441

442+
void foo10() {
443+
vi4 a = {1, 2, 3, 4};
444+
uvi4 b = {5u, 6u, 7u, 8u};
445+
446+
vi4 shl = a << b;
447+
uvi4 shr = b >> a;
448+
}
449+
450+
// CIR: %[[VEC_A:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["a", init]
451+
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>, ["b", init]
452+
// CIR: %[[SHL_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shl", init]
453+
// CIR: %[[SHR_RES:.*]] = cir.alloca !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>, ["shr", init]
454+
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
455+
// CIR: cir.store %[[VEC_A_VAL]], %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
456+
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : !u32i, !u32i, !u32i, !u32i) : !cir.vector<4 x !u32i>
457+
// CIR: cir.store %[[VEC_B_VAL]], %[[VEC_B]] : !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>
458+
// CIR: %[[TMP_A:.*]] = cir.load %[[VEC_A]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
459+
// CIR: %[[TMP_B:.*]] = cir.load %[[VEC_B]] : !cir.ptr<!cir.vector<4 x !u32i>>, !cir.vector<4 x !u32i>
460+
// CIR: %[[SHL:.*]] = cir.shift(left, %[[TMP_A]] : !cir.vector<4 x !s32i>, %[[TMP_B]] : !cir.vector<4 x !u32i>) -> !cir.vector<4 x !s32i>
461+
// CIR: cir.store %[[SHL]], %[[SHL_RES]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
462+
// CIR: %[[TMP_B:.*]] = cir.load %[[VEC_B]] : !cir.ptr<!cir.vector<4 x !u32i>>, !cir.vector<4 x !u32i>
463+
// CIR: %[[TMP_A:.*]] = cir.load %[[VEC_A]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
464+
// CIR: %[[SHR:.*]] = cir.shift(right, %[[TMP_B]] : !cir.vector<4 x !u32i>, %[[TMP_A]] : !cir.vector<4 x !s32i>) -> !cir.vector<4 x !u32i>
465+
// CIR: cir.store %[[SHR]], %[[SHR_RES]] : !cir.vector<4 x !u32i>, !cir.ptr<!cir.vector<4 x !u32i>>
466+
467+
// LLVM: %[[VEC_A:.*]] = alloca <4 x i32>, i64 1, align 16
468+
// LLVM: %[[VEC_B:.*]] = alloca <4 x i32>, i64 1, align 16
469+
// LLVM: %[[SHL_RES:.*]] = alloca <4 x i32>, i64 1, align 16
470+
// LLVM: %[[SHR_RES:.*]] = alloca <4 x i32>, i64 1, align 16
471+
// LLVM: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_A]], align 16
472+
// LLVM: store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, ptr %[[VEC_B]], align 16
473+
// LLVM: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
474+
// LLVM: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
475+
// LLVM: %[[SHL:.*]] = shl <4 x i32> %[[TMP_A]], %[[TMP_B]]
476+
// LLVM: store <4 x i32> %[[SHL]], ptr %[[SHL_RES]], align 16
477+
// LLVM: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
478+
// LLVM: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
479+
// LLVM: %[[SHR:.*]] = lshr <4 x i32> %[[TMP_B]], %[[TMP_A]]
480+
// LLVM: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16
481+
482+
// OGCG: %[[VEC_A:.*]] = alloca <4 x i32>, align 16
483+
// OGCG: %[[VEC_B:.*]] = alloca <4 x i32>, align 16
484+
// OGCG: %[[SHL_RES:.*]] = alloca <4 x i32>, align 16
485+
// OGCG: %[[SHR_RES:.*]] = alloca <4 x i32>, align 16
486+
// OGCG: store <4 x i32> <i32 1, i32 2, i32 3, i32 4>, ptr %[[VEC_A]], align 16
487+
// OGCG: store <4 x i32> <i32 5, i32 6, i32 7, i32 8>, ptr %[[VEC_B]], align 16
488+
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
489+
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
490+
// OGCG: %[[SHL:.*]] = shl <4 x i32> %[[TMP_A]], %[[TMP_B]]
491+
// OGCG: store <4 x i32> %[[SHL]], ptr %[[SHL_RES]], align 16
492+
// OGCG: %[[TMP_B:.*]] = load <4 x i32>, ptr %[[VEC_B]], align 16
493+
// OGCG: %[[TMP_A:.*]] = load <4 x i32>, ptr %[[VEC_A]], align 16
494+
// OGCG: %[[SHR:.*]] = lshr <4 x i32> %[[TMP_B]], %[[TMP_A]]
495+
// OGCG: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16
496+
452497
void foo11() {
453498
vi4 a = {1, 2, 3, 4};
454499
vi4 b = {5, 6, 7, 8};

0 commit comments

Comments
 (0)