2015-02-25 13:48:23 +08:00
|
|
|
// RUN: %clang_cc1 -x cl -O1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -check-prefix=OPT
|
|
|
|
// RUN: %clang_cc1 -x cl -O0 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -check-prefix=NOOPT
|
2013-01-08 00:43:27 +08:00
|
|
|
|
2015-02-25 13:48:23 +08:00
|
|
|
// OpenCL essentially reduces all shift amounts to the last word-size
|
|
|
|
// bits before evaluating. Test this both for variables and constants
|
|
|
|
// evaluated in the front-end.
|
2013-01-08 00:43:27 +08:00
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// OPT: @gtest1 ={{.*}} local_unnamed_addr constant i64 2147483648
|
2015-02-25 13:48:23 +08:00
|
|
|
__constant const unsigned long gtest1 = 1UL << 31;
|
|
|
|
|
|
|
|
// NOOPT: @negativeShift32
|
|
|
|
int negativeShift32(int a,int b) {
|
|
|
|
// NOOPT: %array0 = alloca [256 x i8]
|
|
|
|
char array0[((int)1)<<40];
|
|
|
|
// NOOPT: %array1 = alloca [256 x i8]
|
|
|
|
char array1[((int)1)<<(-24)];
|
|
|
|
|
|
|
|
// NOOPT: ret i32 65536
|
|
|
|
return ((int)1)<<(-16);
|
|
|
|
}
|
|
|
|
|
|
|
|
//OPT: @positiveShift32
|
2013-01-08 00:43:27 +08:00
|
|
|
int positiveShift32(int a,int b) {
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT: [[M32:%.+]] = and i32 %b, 31
|
|
|
|
//OPT-NEXT: [[C32:%.+]] = shl i32 %a, [[M32]]
|
2013-01-08 00:43:27 +08:00
|
|
|
int c = a<<b;
|
|
|
|
int d = ((int)1)<<33;
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT-NEXT: [[E32:%.+]] = add nsw i32 [[C32]], 2
|
2013-01-08 00:43:27 +08:00
|
|
|
int e = c + d;
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT-NEXT: ret i32 [[E32]]
|
2013-01-08 00:43:27 +08:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT: @positiveShift64
|
2013-01-08 00:43:27 +08:00
|
|
|
long positiveShift64(long a,long b) {
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT: [[M64:%.+]] = and i64 %b, 63
|
|
|
|
//OPT-NEXT: [[C64:%.+]] = ashr i64 %a, [[M64]]
|
2013-01-08 00:43:27 +08:00
|
|
|
long c = a>>b;
|
|
|
|
long d = ((long)8)>>65;
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT-NEXT: [[E64:%.+]] = add nsw i64 [[C64]], 4
|
2013-01-08 00:43:27 +08:00
|
|
|
long e = c + d;
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT-NEXT: ret i64 [[E64]]
|
2013-01-08 00:43:27 +08:00
|
|
|
return e;
|
|
|
|
}
|
2013-01-10 18:42:08 +08:00
|
|
|
|
|
|
|
typedef __attribute__((ext_vector_type(4))) int int4;
|
|
|
|
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT: @vectorVectorTest
|
2013-01-10 18:42:08 +08:00
|
|
|
int4 vectorVectorTest(int4 a,int4 b) {
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT: [[VM:%.+]] = and <4 x i32> %b, <i32 31, i32 31, i32 31, i32 31>
|
|
|
|
//OPT-NEXT: [[VC:%.+]] = shl <4 x i32> %a, [[VM]]
|
2013-01-10 18:42:08 +08:00
|
|
|
int4 c = a << b;
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT-NEXT: [[VF:%.+]] = add <4 x i32> [[VC]], <i32 2, i32 4, i32 16, i32 8>
|
2013-01-10 18:42:08 +08:00
|
|
|
int4 d = {1, 1, 1, 1};
|
|
|
|
int4 e = {33, 34, -28, -29};
|
|
|
|
int4 f = c + (d << e);
|
2015-02-25 13:48:23 +08:00
|
|
|
//OPT-NEXT: ret <4 x i32> [[VF]]
|
2013-01-10 18:42:08 +08:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2018-05-16 22:38:07 +08:00
|
|
|
//NOOPT-LABEL: @vectorScalarTest
|
2013-01-10 18:42:08 +08:00
|
|
|
int4 vectorScalarTest(int4 a,int b) {
|
2020-12-24 08:33:58 +08:00
|
|
|
//NOOPT: [[SP0:%.+]] = insertelement <4 x i32> poison
|
|
|
|
//NOOPT: [[SP1:%.+]] = shufflevector <4 x i32> [[SP0]], <4 x i32> poison, <4 x i32> zeroinitializer
|
2018-05-16 22:38:07 +08:00
|
|
|
//NOOPT: [[VSM:%.+]] = and <4 x i32> [[SP1]], <i32 31, i32 31, i32 31, i32 31>
|
|
|
|
//NOOPT: [[VSC:%.+]] = shl <4 x i32> [[VSS:%.+]], [[VSM]]
|
2013-01-10 18:42:08 +08:00
|
|
|
int4 c = a << b;
|
2018-05-16 22:38:07 +08:00
|
|
|
//NOOPT: [[VSF:%.+]] = shl <4 x i32> [[VSC1:%.+]], <i32 2, i32 2, i32 2, i32 2>
|
|
|
|
//NOOPT: [[VSA:%.+]] = add <4 x i32> [[VSC2:%.+]], [[VSF]]
|
2013-01-10 18:42:08 +08:00
|
|
|
int4 d = {1, 1, 1, 1};
|
|
|
|
int4 f = c + (d << 34);
|
2018-05-16 22:38:07 +08:00
|
|
|
//NOOPT: ret <4 x i32>
|
2013-01-10 18:42:08 +08:00
|
|
|
return f;
|
|
|
|
}
|