Skip to content

Commit 6b6ea93

Browse files
author
Kai Luo
committed
[PowerPC][altivec] Correct modulo number of vec_promote on vector char
According to https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.1?topic=functions-vec-promote, the index should be input modulo the number of elements in the vector. When the type is `vector char`, the number of elements should be 16. Reviewed By: qiucf Differential Revision: https://reviews.llvm.org/D158484
1 parent 668f261 commit 6b6ea93

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

clang/lib/Headers/altivec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14648,14 +14648,14 @@ static __inline__ void __ATTRS_o_ai vec_stvrxl(vector float __a, int __b,
1464814648
static __inline__ vector signed char __ATTRS_o_ai vec_promote(signed char __a,
1464914649
int __b) {
1465014650
vector signed char __res = (vector signed char)(0);
14651-
__res[__b & 0x7] = __a;
14651+
__res[__b & 0xf] = __a;
1465214652
return __res;
1465314653
}
1465414654

1465514655
static __inline__ vector unsigned char __ATTRS_o_ai
1465614656
vec_promote(unsigned char __a, int __b) {
1465714657
vector unsigned char __res = (vector unsigned char)(0);
14658-
__res[__b & 0x7] = __a;
14658+
__res[__b & 0xf] = __a;
1465914659
return __res;
1466014660
}
1466114661

clang/test/CodeGen/PowerPC/builtins-ppc-vsx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,18 +2250,18 @@ res_vull = vec_promote(ull, 0);
22502250

22512251
res_vsc = vec_promote(asc[0], 8);
22522252
// CHECK: store <16 x i8> zeroinitializer
2253-
// CHECK: [[IDX:%.*]] = and i32 {{.*}}, 7
2253+
// CHECK: [[IDX:%.*]] = and i32 {{.*}}, 15
22542254
// CHECK: insertelement <16 x i8> {{.*}}, i8 {{.*}}, i32 [[IDX]]
22552255
// CHECK-LE: store <16 x i8> zeroinitializer
2256-
// CHECK-LE: [[IDX:%.*]] = and i32 {{.*}}, 7
2256+
// CHECK-LE: [[IDX:%.*]] = and i32 {{.*}}, 15
22572257
// CHECK-LE: insertelement <16 x i8> {{.*}}, i8 {{.*}}, i32 [[IDX]]
22582258

22592259
res_vuc = vec_promote(auc[0], 8);
22602260
// CHECK: store <16 x i8> zeroinitializer
2261-
// CHECK: [[IDX:%.*]] = and i32 {{.*}}, 7
2261+
// CHECK: [[IDX:%.*]] = and i32 {{.*}}, 15
22622262
// CHECK: insertelement <16 x i8> {{.*}}, i8 {{.*}}, i32 [[IDX]]
22632263
// CHECK-LE: store <16 x i8> zeroinitializer
2264-
// CHECK-LE: [[IDX:%.*]] = and i32 {{.*}}, 7
2264+
// CHECK-LE: [[IDX:%.*]] = and i32 {{.*}}, 15
22652265
// CHECK-LE: insertelement <16 x i8> {{.*}}, i8 {{.*}}, i32 [[IDX]]
22662266
}
22672267

0 commit comments

Comments
 (0)