diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index be0d7be628a2..dec1a01f2063 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -2802,7 +2802,11 @@ class CIRShiftOpLowering if (op.getIsShiftleft()) rewriter.replaceOpWithNewOp(op, llvmTy, val, amt); else { - if (cirValTy.isUnsigned()) + bool isUnSigned = + cirValTy ? !cirValTy.isSigned() + : !mlir::cast(cirValVTy.getEltType()) + .isSigned(); + if (isUnSigned) rewriter.replaceOpWithNewOp(op, llvmTy, val, amt); else rewriter.replaceOpWithNewOp(op, llvmTy, val, amt); diff --git a/clang/test/CIR/CodeGen/vectype.cpp b/clang/test/CIR/CodeGen/vectype.cpp index 1f6076f7f49d..4fd9302dc4cf 100644 --- a/clang/test/CIR/CodeGen/vectype.cpp +++ b/clang/test/CIR/CodeGen/vectype.cpp @@ -5,7 +5,7 @@ typedef double vd2 __attribute__((vector_size(16))); typedef long long vll2 __attribute__((vector_size(16))); typedef unsigned short vus2 __attribute__((vector_size(4))); -void vector_int_test(int x) { +void vector_int_test(int x, unsigned short usx) { // Vector constant. vi4 a = { 1, 2, 3, 4 }; @@ -102,6 +102,22 @@ void vector_int_test(int x) { // CHECK: %{{[0-9]+}} = cir.vec.shuffle(%{{[0-9]+}}, %{{[0-9]+}} : !cir.vector) [#cir.int<7> : !s64i, #cir.int<5> : !s64i, #cir.int<3> : !s64i, #cir.int<1> : !s64i] : !cir.vector vi4 v = __builtin_shufflevector(a, b); // CHECK: %{{[0-9]+}} = cir.vec.shuffle.dynamic %{{[0-9]+}} : !cir.vector, %{{[0-9]+}} : !cir.vector + + // Shifts + vi4 w = a << b; + // CHECK: %{{[0-9]+}} = cir.shift(left, {{%.*}} : !cir.vector, + // CHECK-SAME: {{%.*}} : !cir.vector) -> !cir.vector + vi4 y = a >> b; + // CHECK: %{{[0-9]+}} = cir.shift( right, {{%.*}} : !cir.vector, + // CHECK-SAME: {{%.*}} : !cir.vector) -> !cir.vector + + vus2 z = { usx, usx }; + // CHECK: %{{[0-9]+}} = cir.vec.create(%{{[0-9]+}}, %{{[0-9]+}} : !u16i, !u16i) : !cir.vector + vus2 zamt = { 3, 4 }; + // CHECK: %{{[0-9]+}} = cir.const #cir.const_vector<[#cir.int<3> : !u16i, #cir.int<4> : !u16i]> : !cir.vector + vus2 zzz = z >> zamt; + // CHECK: %{{[0-9]+}} = cir.shift( right, {{%.*}} : !cir.vector, + // CHECK-SAME: {{%.*}} : !cir.vector) -> !cir.vector } void vector_double_test(int x, double y) { diff --git a/clang/test/CIR/Lowering/vectype.cpp b/clang/test/CIR/Lowering/vectype.cpp index 56fbdd3df225..fa21d3f6339c 100644 --- a/clang/test/CIR/Lowering/vectype.cpp +++ b/clang/test/CIR/Lowering/vectype.cpp @@ -219,6 +219,24 @@ void vector_int_test(int x) { // CHECK: %[[#svQ:]] = llvm.extractelement %[[#sv_a]][%[[#svP:]] : i32] : vector<4xi32> // CHECK: %[[#svR:]] = llvm.insertelement %[[#svQ]], %[[#svN]][%[[#svO]] : i64] : vector<4xi32> // CHECK: llvm.store %[[#svR]], %[[#sv_v:]] {alignment = 16 : i64} : vector<4xi32>, !llvm.ptr + + // Shifts + vi4 w = a << b; + // CHECK: %[[#T198:]] = llvm.load %[[#T3]] {alignment = 16 : i64} : !llvm.ptr -> vector<4xi32> + // CHECK: %[[#T199:]] = llvm.load %[[#T5]] {alignment = 16 : i64} : !llvm.ptr -> vector<4xi32> + // CHECK: %{{[0-9]+}} = llvm.shl %[[#T198]], %[[#T199]] : vector<4xi32> + vi4 y = a >> b; + // CHECK: %[[#T201:]] = llvm.load %[[#T3]] {alignment = 16 : i64} : !llvm.ptr -> vector<4xi32> + // CHECK: %[[#T202:]] = llvm.load %[[#T5]] {alignment = 16 : i64} : !llvm.ptr -> vector<4xi32> + // CHECK: %{{[0-9]+}} = llvm.ashr %[[#T201]], %[[#T202]] : vector<4xi32> + + vus2 z = { (unsigned short)x, (unsigned short)x }; + vus2 zamt = { 3, 4 }; + // CHECK: %[[#T219:]] = llvm.mlir.constant(dense<[3, 4]> : vector<2xi16>) : vector<2xi16> + // CHECK: llvm.store %[[#T219]], %[[#AMT_SAVE:]] {alignment = 4 : i64} : vector<2xi16> + // CHECK: %[[#T221:]] = llvm.load %[[#AMT_SAVE]] {alignment = 4 : i64} : !llvm.ptr -> vector<2xi16> + vus2 zzz = z >> zamt; + // CHECK: %{{[0-9]+}} = llvm.lshr %{{[0-9]+}}, %[[#T221]] : vector<2xi16> } void vector_double_test(int x, double y) {