Skip to content

Commit af8ef3a

Browse files
committed
address review comments
1 parent 6ec9aa5 commit af8ef3a

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11315,16 +11315,16 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1131511315
if (!EvaluateAsRValue(Info, E->getArg(0), Source))
1131611316
return false;
1131711317

11318-
QualType DestTy = E->getType()->castAs<VectorType>()->getElementType();
11318+
QualType DestEltTy = E->getType()->castAs<VectorType>()->getElementType();
1131911319
unsigned SourceLen = Source.getVectorLength();
1132011320
SmallVector<APValue, 4> ResultElements;
1132111321
ResultElements.reserve(SourceLen);
1132211322

1132311323
for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
1132411324
APSInt Elt = Source.getVectorElt(EltNum).getInt();
1132511325
ResultElements.push_back(
11326-
APValue(APSInt(APInt(Info.Ctx.getIntWidth(DestTy), Elt.popcount()),
11327-
DestTy->isUnsignedIntegerOrEnumerationType())));
11326+
APValue(APSInt(APInt(Info.Ctx.getIntWidth(DestEltTy), Elt.popcount()),
11327+
DestEltTy->isUnsignedIntegerOrEnumerationType())));
1132811328
}
1132911329

1133011330
return Success(APValue(ResultElements.data(), ResultElements.size()), E);

clang/test/CodeGen/builtins-elementwise-math.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,35 @@ void test_builtin_elementwise_log2(float f1, float f2, double d1, double d2,
669669
void test_builtin_elementwise_popcount(si8 vi1, si8 vi2, long long int i1,
670670
long long int i2, short si,
671671
_BitInt(31) bi1, _BitInt(31) bi2) {
672+
// CHECK: [[I1:%.+]] = load i64, ptr %i1.addr, align 8
673+
// CHECK-NEXT: call i64 @llvm.ctpop.i64(i64 [[I1]])
672674
i2 = __builtin_elementwise_popcount(i1);
675+
676+
// CHECK: [[VI1:%.+]] = load <8 x i16>, ptr %vi1.addr, align 16
677+
// CHECK-NEXT: call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> [[VI1]])
673678
vi2 = __builtin_elementwise_popcount(vi1);
679+
680+
// CHECK: [[CVI2:%.+]] = load <8 x i16>, ptr %cvi2, align 16
681+
// CHECK-NEXT: call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> [[CVI2]])
674682
const si8 cvi2 = vi2;
675683
vi2 = __builtin_elementwise_popcount(cvi2);
684+
685+
// CHECK: [[BI1:%.+]] = load i32, ptr %bi1.addr, align 4
686+
// CHECK-NEXT: [[LOADEDV:%.+]] = trunc i32 [[BI1]] to i31
687+
// CHECK-NEXT: call i31 @llvm.ctpop.i31(i31 [[LOADEDV]])
676688
bi2 = __builtin_elementwise_popcount(bi1);
689+
690+
// CHECK: [[IA1:%.+]] = load i32, ptr addrspace(1) @int_as_one, align 4
691+
// CHECK-NEXT: call i32 @llvm.ctpop.i32(i32 [[IA1]])
677692
b = __builtin_elementwise_popcount(int_as_one);
693+
694+
// CHECK: store i32 30, ptr @b, align 4
678695
b = __builtin_elementwise_popcount(-10);
696+
697+
// CHECK: [[SI:%.+]] = load i16, ptr %si.addr, align 2
698+
// CHECK-NEXT: [[SI_EXT:%.+]] = sext i16 [[SI]] to i32
699+
// CHECK-NEXT: [[RES:%.+]] = call i32 @llvm.ctpop.i32(i32 [[SI_EXT]])
700+
// CHECK-NEXT: = trunc i32 [[RES]] to i16
679701
si = __builtin_elementwise_popcount(si);
680702
}
681703

clang/test/Sema/constant_builtins_vector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ static_assert(__builtin_reduce_xor((vector4long){(long long)0x1111111111111111L,
798798
static_assert(__builtin_reduce_xor((vector4uint){0x11111111U, 0x22222222U, 0x44444444U, 0x88888888U}) == 0xFFFFFFFFU);
799799
static_assert(__builtin_reduce_xor((vector4ulong){0x1111111111111111UL, 0x2222222222222222UL, 0x4444444444444444UL, 0x8888888888888888UL}) == 0xFFFFFFFFFFFFFFFFUL);
800800

801+
static_assert(__builtin_bit_cast(unsigned, __builtin_elementwise_popcount((vector4char){1, 2, 3, 4})) == (LITTLE_END ? 0x01020101 : 0x01010201));
802+
static_assert(__builtin_bit_cast(unsigned long, __builtin_elementwise_popcount((vector4short){0, 0x0F0F, ~0, ~0x0F0F})) == (LITTLE_END ? 0x0008001000080000 : 0x0000000800100008));
801803
static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){1, 2, 3, 4})) == 5);
802804
static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4int){0, 0xF0F0, ~0, ~0xF0F0})) == 16 * sizeof(int));
803805
static_assert(__builtin_reduce_add(__builtin_elementwise_popcount((vector4long){1L, 2L, 3L, 4L})) == 5L);

0 commit comments

Comments
 (0)