| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 1 | ; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=%S -polly-codegen -S < %s | FileCheck %s |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 2 | ; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=%S -polly-codegen -polly-import-jscop-postfix=pow2 -S < %s | FileCheck %s -check-prefix=POW2 |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 3 | ; |
| 4 | ; void exprModDiv(float *A, float *B, float *C, long N, long p) { |
| 5 | ; for (long i = 0; i < N; i++) |
| 6 | ; C[i] += A[i] + B[i] + A[p] + B[p]; |
| 7 | ; } |
| 8 | ; |
| 9 | ; |
| 10 | ; This test case changes the access functions such that the resulting index |
| 11 | ; expressions are modulo or division operations. We test that the code we |
| 12 | ; generate takes advantage of knowledge about unsigned numerators. This is |
| 13 | ; useful as LLVM will translate urem and udiv operations with power-of-two |
| 14 | ; denominators to fast bitwise and or shift operations. |
| 15 | |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 16 | ; A[i % 127] |
| 17 | ; CHECK: %pexp.pdiv_r = urem i64 %polly.indvar, 127 |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 18 | ; CHECK: %polly.access.A6 = getelementptr float, float* %A, i64 %pexp.pdiv_r |
| 19 | |
| Tobias Grosser | 5cf7860 | 2015-06-04 07:44:35 +0000 | [diff] [blame] | 20 | ; A[floor(i / 127)] |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 21 | ; |
| Tobias Grosser | 5cf7860 | 2015-06-04 07:44:35 +0000 | [diff] [blame] | 22 | ; Note: without the floor, we would create a map i -> i/127, which only contains |
| 23 | ; values of i that are divisible by 127. All other values of i would not |
| 24 | ; be mapped to any value. However, to generate correct code we require |
| 25 | ; each value of i to indeed be mapped to a value. |
| 26 | ; |
| 27 | ; CHECK: %pexp.p_div_q = udiv i64 %polly.indvar, 127 |
| 28 | ; CHECK: %polly.access.B8 = getelementptr float, float* %B, i64 %pexp.p_div_q |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 29 | |
| 30 | ; #define floord(n,d) ((n < 0) ? (n - d + 1) : n) / d |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 31 | ; A[p + 127 * floord(-p - 1, 127) + 127] |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 32 | ; CHECK: %20 = sub nsw i64 0, %p |
| 33 | ; CHECK: %21 = sub nsw i64 %20, 1 |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 34 | ; CHECK: %pexp.fdiv_q.0 = sub i64 %21, 127 |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 35 | ; CHECK: %pexp.fdiv_q.1 = add i64 %pexp.fdiv_q.0, 1 |
| 36 | ; CHECK: %pexp.fdiv_q.2 = icmp slt i64 %21, 0 |
| 37 | ; CHECK: %pexp.fdiv_q.3 = select i1 %pexp.fdiv_q.2, i64 %pexp.fdiv_q.1, i64 %21 |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 38 | ; CHECK: %pexp.fdiv_q.4 = sdiv i64 %pexp.fdiv_q.3, 127 |
| 39 | ; CHECK: %22 = mul nsw i64 127, %pexp.fdiv_q.4 |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 40 | ; CHECK: %23 = add nsw i64 %p, %22 |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 41 | ; CHECK: %24 = add nsw i64 %23, 127 |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 42 | ; CHECK: %polly.access.A10 = getelementptr float, float* %A, i64 %24 |
| 43 | |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 44 | ; A[p / 127] |
| Tobias Grosser | 22adfb4 | 2015-06-04 07:45:09 +0000 | [diff] [blame^] | 45 | ; CHECK: %pexp.div = sdiv exact i64 %p, 127 |
| Tobias Grosser | 5cf7860 | 2015-06-04 07:44:35 +0000 | [diff] [blame] | 46 | ; CHECK: %polly.access.B12 = getelementptr float, float* %B, i64 %pexp.div |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 47 | |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 48 | ; A[i % 128] |
| 49 | ; POW2: %pexp.pdiv_r = urem i64 %polly.indvar, 128 |
| 50 | ; POW2: %polly.access.A6 = getelementptr float, float* %A, i64 %pexp.pdiv_r |
| 51 | |
| Tobias Grosser | 5cf7860 | 2015-06-04 07:44:35 +0000 | [diff] [blame] | 52 | ; A[floor(i / 128)] |
| 53 | ; POW2: %pexp.p_div_q = udiv i64 %polly.indvar, 128 |
| 54 | ; POW2: %polly.access.B8 = getelementptr float, float* %B, i64 %pexp.p_div_q |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 55 | |
| 56 | ; #define floord(n,d) ((n < 0) ? (n - d + 1) : n) / d |
| 57 | ; A[p + 128 * floord(-p - 1, 128) + 128] |
| 58 | ; POW2: %20 = sub nsw i64 0, %p |
| 59 | ; POW2: %21 = sub nsw i64 %20, 1 |
| 60 | ; POW2: %polly.fdiv_q.shr = ashr i64 %21, 7 |
| 61 | ; POW2: %22 = mul nsw i64 128, %polly.fdiv_q.shr |
| 62 | ; POW2: %23 = add nsw i64 %p, %22 |
| 63 | ; POW2: %24 = add nsw i64 %23, 128 |
| 64 | ; POW2: %polly.access.A10 = getelementptr float, float* %A, i64 %24 |
| 65 | |
| 66 | ; A[p / 128] |
| Tobias Grosser | 22adfb4 | 2015-06-04 07:45:09 +0000 | [diff] [blame^] | 67 | ; POW2: %pexp.div = sdiv exact i64 %p, 128 |
| 68 | ; POW2: %polly.access.B12 = getelementptr float, float* %B, i64 %pexp.div |
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 69 | |
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 70 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 71 | |
| 72 | define void @exprModDiv(float* %A, float* %B, float* %C, i64 %N, i64 %p) { |
| 73 | entry: |
| 74 | br label %for.cond |
| 75 | |
| 76 | for.cond: ; preds = %for.inc, %entry |
| 77 | %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ] |
| 78 | %cmp = icmp slt i64 %i.0, %N |
| 79 | br i1 %cmp, label %for.body, label %for.end |
| 80 | |
| 81 | for.body: ; preds = %for.cond |
| 82 | %arrayidx = getelementptr inbounds float, float* %A, i64 %i.0 |
| 83 | %tmp = load float, float* %arrayidx, align 4 |
| 84 | %arrayidx1 = getelementptr inbounds float, float* %B, i64 %i.0 |
| 85 | %tmp1 = load float, float* %arrayidx1, align 4 |
| 86 | %add = fadd float %tmp, %tmp1 |
| 87 | %arrayidx2 = getelementptr inbounds float, float* %A, i64 %p |
| 88 | %tmp2 = load float, float* %arrayidx2, align 4 |
| 89 | %add3 = fadd float %add, %tmp2 |
| 90 | %arrayidx4 = getelementptr inbounds float, float* %B, i64 %p |
| 91 | %tmp3 = load float, float* %arrayidx4, align 4 |
| 92 | %add5 = fadd float %add3, %tmp3 |
| 93 | %arrayidx6 = getelementptr inbounds float, float* %C, i64 %i.0 |
| 94 | %tmp4 = load float, float* %arrayidx6, align 4 |
| 95 | %add7 = fadd float %tmp4, %add5 |
| 96 | store float %add7, float* %arrayidx6, align 4 |
| 97 | br label %for.inc |
| 98 | |
| 99 | for.inc: ; preds = %for.body |
| 100 | %inc = add nuw nsw i64 %i.0, 1 |
| 101 | br label %for.cond |
| 102 | |
| 103 | for.end: ; preds = %for.cond |
| 104 | ret void |
| 105 | } |