Skip to content

Commit 2a56a5d

Browse files
committed
[CIR] Allow use different Int types together in Vec Shift Op
1 parent 0ee40ca commit 2a56a5d

File tree

2 files changed

+60
-14
lines changed

2 files changed

+60
-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: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
77

88
typedef int vi4 __attribute__((vector_size(16)));
9+
typedef unsigned int uvi4 __attribute__((vector_size(16)));
910
typedef double vd2 __attribute__((vector_size(16)));
1011
typedef long long vll2 __attribute__((vector_size(16)));
1112

@@ -394,19 +395,9 @@ void foo9() {
394395
// CIR: %[[VEC_B:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["b", init]
395396
// CIR: %[[SHL_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shl", init]
396397
// CIR: %[[SHR_RES:.*]] = cir.alloca !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>, ["shr", init]
397-
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
398-
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
399-
// CIR: %[[CONST_3:.*]] = cir.const #cir.int<3> : !s32i
400-
// CIR: %[[CONST_4:.*]] = cir.const #cir.int<4> : !s32i
401-
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%[[CONST_1]], %[[CONST_2]], %[[CONST_3]], %[[CONST_4]] :
402-
// CIR-SAME: !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
398+
// CIR: %[[VEC_A_VAL:.*]] = cir.vec.create(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
403399
// CIR: cir.store %[[VEC_A_VAL]], %[[VEC_A]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
404-
// CIR: %[[CONST_5:.*]] = cir.const #cir.int<5> : !s32i
405-
// CIR: %[[CONST_6:.*]] = cir.const #cir.int<6> : !s32i
406-
// CIR: %[[CONST_7:.*]] = cir.const #cir.int<7> : !s32i
407-
// CIR: %[[CONST_8:.*]] = cir.const #cir.int<8> : !s32i
408-
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%[[CONST_5]], %[[CONST_6]], %[[CONST_7]], %[[CONST_8]] :
409-
// CIR-SAME: !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
400+
// CIR: %[[VEC_B_VAL:.*]] = cir.vec.create(%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}} : !s32i, !s32i, !s32i, !s32i) : !cir.vector<4 x !s32i>
410401
// CIR: cir.store %[[VEC_B_VAL]], %[[VEC_B]] : !cir.vector<4 x !s32i>, !cir.ptr<!cir.vector<4 x !s32i>>
411402
// CIR: %[[TMP_A:.*]] = cir.load %[[VEC_A]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
412403
// CIR: %[[TMP_B:.*]] = cir.load %[[VEC_B]] : !cir.ptr<!cir.vector<4 x !s32i>>, !cir.vector<4 x !s32i>
@@ -447,6 +438,61 @@ void foo9() {
447438
// OGCG: %[[SHR:.*]] = ashr <4 x i32> %[[TMP_A]], %[[TMP_B]]
448439
// OGCG: store <4 x i32> %[[SHR]], ptr %[[SHR_RES]], align 16
449440

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

0 commit comments

Comments
 (0)