blob: 015a77711a681b2d5b8c881ede202eb48e99161f [file] [log] [blame]
David Tweed7a834212013-01-07 16:43:27 +00001// RUN: %clang_cc1 -x cl -O1 -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
2// OpenCL essentially reduces all shift amounts to the last word-size bits before evaluating.
3// Test this both for variables and constants evaluated in the front-end.
4
5
6//CHECK: @positiveShift32
7int positiveShift32(int a,int b) {
NAKAMURA Takumi66479862013-01-08 00:15:53 +00008 //CHECK: [[M32:%.+]] = and i32 %b, 31
9 //CHECK-NEXT: [[C32:%.+]] = shl i32 %a, [[M32]]
David Tweed7a834212013-01-07 16:43:27 +000010 int c = a<<b;
11 int d = ((int)1)<<33;
NAKAMURA Takumi66479862013-01-08 00:15:53 +000012 //CHECK-NEXT: [[E32:%.+]] = add nsw i32 [[C32]], 2
David Tweed7a834212013-01-07 16:43:27 +000013 int e = c + d;
NAKAMURA Takumi66479862013-01-08 00:15:53 +000014 //CHECK-NEXT: ret i32 [[E32]]
David Tweed7a834212013-01-07 16:43:27 +000015 return e;
16}
17
18//CHECK: @positiveShift64
19long positiveShift64(long a,long b) {
NAKAMURA Takumi66479862013-01-08 00:15:53 +000020 //CHECK: [[M64:%.+]] = and i64 %b, 63
21 //CHECK-NEXT: [[C64:%.+]] = ashr i64 %a, [[M64]]
David Tweed7a834212013-01-07 16:43:27 +000022 long c = a>>b;
23 long d = ((long)8)>>65;
NAKAMURA Takumi66479862013-01-08 00:15:53 +000024 //CHECK-NEXT: [[E64:%.+]] = add nsw i64 [[C64]], 4
David Tweed7a834212013-01-07 16:43:27 +000025 long e = c + d;
NAKAMURA Takumi66479862013-01-08 00:15:53 +000026 //CHECK-NEXT: ret i64 [[E64]]
David Tweed7a834212013-01-07 16:43:27 +000027 return e;
28}
David Tweeda2d37a52013-01-10 10:42:08 +000029
30typedef __attribute__((ext_vector_type(4))) int int4;
31
32//CHECK: @vectorVectorTest
33int4 vectorVectorTest(int4 a,int4 b) {
34 //CHECK: [[VM:%.+]] = and <4 x i32> %b, <i32 31, i32 31, i32 31, i32 31>
35 //CHECK-NEXT: [[VC:%.+]] = shl <4 x i32> %a, [[VM]]
36 int4 c = a << b;
37 //CHECK-NEXT: [[VF:%.+]] = add <4 x i32> [[VC]], <i32 2, i32 4, i32 16, i32 8>
38 int4 d = {1, 1, 1, 1};
39 int4 e = {33, 34, -28, -29};
40 int4 f = c + (d << e);
41 //CHECK-NEXT: ret <4 x i32> [[VF]]
42 return f;
43}
44
45//CHECK: @vectorScalarTest
46int4 vectorScalarTest(int4 a,int b) {
47 //CHECK: [[SP0:%.+]] = insertelement <4 x i32> undef, i32 %b, i32 0
48 //CHECK: [[SP1:%.+]] = shufflevector <4 x i32> [[SP0]], <4 x i32> undef, <4 x i32> zeroinitializer
49 //CHECK: [[VSM:%.+]] = and <4 x i32> [[SP1]], <i32 31, i32 31, i32 31, i32 31>
50 //CHECK-NEXT: [[VSC:%.+]] = shl <4 x i32> %a, [[VSM]]
51 int4 c = a << b;
52 //CHECK-NEXT: [[VSF:%.+]] = add <4 x i32> [[VSC]], <i32 4, i32 4, i32 4, i32 4>
53 int4 d = {1, 1, 1, 1};
54 int4 f = c + (d << 34);
55 //CHECK-NEXT: ret <4 x i32> [[VSF]]
56 return f;
57}