David Tweed | 7a83421 | 2013-01-07 16:43:27 +0000 | [diff] [blame] | 1 | // 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 |
| 7 | int positiveShift32(int a,int b) { |
| 8 | //CHECK: %shl.mask = and i32 %b, 31 |
| 9 | //CHECK-NEXT: %shl = shl i32 %a, %shl.mask |
| 10 | int c = a<<b; |
| 11 | int d = ((int)1)<<33; |
| 12 | //CHECK-NEXT: %add = add nsw i32 %shl, 2 |
| 13 | int e = c + d; |
| 14 | //CHECK-NEXT: ret i32 %add |
| 15 | return e; |
| 16 | } |
| 17 | |
| 18 | //CHECK: @positiveShift64 |
| 19 | long positiveShift64(long a,long b) { |
| 20 | //CHECK: %shr.mask = and i64 %b, 63 |
| 21 | //CHECK-NEXT: %shr = ashr i64 %a, %shr.mask |
| 22 | long c = a>>b; |
| 23 | long d = ((long)8)>>65; |
| 24 | //CHECK-NEXT: %add = add nsw i64 %shr, 4 |
| 25 | long e = c + d; |
| 26 | //CHECK-NEXT: ret i64 %add |
| 27 | return e; |
| 28 | } |