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