| Tobias Grosser | ed21a1f | 2015-08-27 16:55:18 +0000 | [diff] [blame] | 1 | ; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=%S \ | 
|  | 2 | ; RUN:     -polly-codegen -polly-detect-unprofitable -S < %s | FileCheck %s | 
|  | 3 | ; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=%S \ | 
|  | 4 | ; RUN:     -polly-codegen -polly-import-jscop-postfix=pow2 \ | 
|  | 5 | ; RUN:     -polly-detect-unprofitable -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 | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 21 | ; CHECK:  %polly.access.A6 = getelementptr float, float* %A, i64 %pexp.pdiv_r | 
|  | 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 | 
| Tobias Grosser | aff56c8 | 2015-09-30 13:36:54 +0000 | [diff] [blame] | 31 | ; CHECK:  %polly.access.B7 = 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 | c1db67e | 2015-09-29 23:47:21 +0000 | [diff] [blame] | 35 | ; CHECK:  %17 = sub nsw i64 0, %p | 
|  | 36 | ; CHECK:  %18 = sub nsw i64 %17, 1 | 
|  | 37 | ; CHECK:  %pexp.fdiv_q.0 = sub i64 %18, 127 | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 38 | ; CHECK:  %pexp.fdiv_q.1 = add i64 %pexp.fdiv_q.0, 1 | 
| Johannes Doerfert | c1db67e | 2015-09-29 23:47:21 +0000 | [diff] [blame] | 39 | ; CHECK:  %pexp.fdiv_q.2 = icmp slt i64 %18, 0 | 
|  | 40 | ; CHECK:  %pexp.fdiv_q.3 = select i1 %pexp.fdiv_q.2, i64 %pexp.fdiv_q.1, i64 %18 | 
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 41 | ; CHECK:  %pexp.fdiv_q.4 = sdiv i64 %pexp.fdiv_q.3, 127 | 
| Johannes Doerfert | c1db67e | 2015-09-29 23:47:21 +0000 | [diff] [blame] | 42 | ; CHECK:  %19 = mul nsw i64 127, %pexp.fdiv_q.4 | 
|  | 43 | ; CHECK:  %20 = add nsw i64 %p, %19 | 
|  | 44 | ; CHECK:  %21 = add nsw i64 %20, 127 | 
| Tobias Grosser | aff56c8 | 2015-09-30 13:36:54 +0000 | [diff] [blame] | 45 | ; CHECK:  %polly.access.A8 = getelementptr float, float* %A, i64 %21 | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 46 |  | 
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 47 | ; A[p / 127] | 
| Tobias Grosser | 22adfb4 | 2015-06-04 07:45:09 +0000 | [diff] [blame] | 48 | ; CHECK:  %pexp.div = sdiv exact i64 %p, 127 | 
| Tobias Grosser | aff56c8 | 2015-09-30 13:36:54 +0000 | [diff] [blame] | 49 | ; CHECK:  %polly.access.B9 = getelementptr float, float* %B, i64 %pexp.div | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 50 |  | 
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 51 | ; A[i % 128] | 
|  | 52 | ; POW2:  %pexp.pdiv_r = urem i64 %polly.indvar, 128 | 
|  | 53 | ; POW2:  %polly.access.A6 = getelementptr float, float* %A, i64 %pexp.pdiv_r | 
|  | 54 |  | 
| Tobias Grosser | 5cf7860 | 2015-06-04 07:44:35 +0000 | [diff] [blame] | 55 | ; A[floor(i / 128)] | 
|  | 56 | ; POW2:  %pexp.p_div_q = udiv i64 %polly.indvar, 128 | 
| Tobias Grosser | aff56c8 | 2015-09-30 13:36:54 +0000 | [diff] [blame] | 57 | ; POW2:  %polly.access.B7 = getelementptr float, float* %B, i64 %pexp.p_div_q | 
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 58 |  | 
|  | 59 | ; #define floord(n,d) ((n < 0) ? (n - d + 1) : n) / d | 
|  | 60 | ; A[p + 128 * floord(-p - 1, 128) + 128] | 
| Johannes Doerfert | c1db67e | 2015-09-29 23:47:21 +0000 | [diff] [blame] | 61 | ; POW2:  %17 = sub nsw i64 0, %p | 
|  | 62 | ; POW2:  %18 = sub nsw i64 %17, 1 | 
|  | 63 | ; POW2:  %polly.fdiv_q.shr = ashr i64 %18, 7 | 
|  | 64 | ; POW2:  %19 = mul nsw i64 128, %polly.fdiv_q.shr | 
|  | 65 | ; POW2:  %20 = add nsw i64 %p, %19 | 
|  | 66 | ; POW2:  %21 = add nsw i64 %20, 128 | 
| Tobias Grosser | aff56c8 | 2015-09-30 13:36:54 +0000 | [diff] [blame] | 67 | ; POW2:  %polly.access.A8 = getelementptr float, float* %A, i64 %21 | 
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | ; A[p / 128] | 
| Tobias Grosser | 22adfb4 | 2015-06-04 07:45:09 +0000 | [diff] [blame] | 70 | ; POW2:  %pexp.div = sdiv exact i64 %p, 128 | 
| Tobias Grosser | aff56c8 | 2015-09-30 13:36:54 +0000 | [diff] [blame] | 71 | ; POW2:  %polly.access.B9 = getelementptr float, float* %B, i64 %pexp.div | 
| Tobias Grosser | cb73f15 | 2015-06-03 06:31:30 +0000 | [diff] [blame] | 72 |  | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 73 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | 
|  | 74 |  | 
|  | 75 | define void @exprModDiv(float* %A, float* %B, float* %C, i64 %N, i64 %p) { | 
|  | 76 | entry: | 
|  | 77 | br label %for.cond | 
|  | 78 |  | 
|  | 79 | for.cond:                                         ; preds = %for.inc, %entry | 
|  | 80 | %i.0 = phi i64 [ 0, %entry ], [ %inc, %for.inc ] | 
|  | 81 | %cmp = icmp slt i64 %i.0, %N | 
|  | 82 | br i1 %cmp, label %for.body, label %for.end | 
|  | 83 |  | 
|  | 84 | for.body:                                         ; preds = %for.cond | 
|  | 85 | %arrayidx = getelementptr inbounds float, float* %A, i64 %i.0 | 
|  | 86 | %tmp = load float, float* %arrayidx, align 4 | 
|  | 87 | %arrayidx1 = getelementptr inbounds float, float* %B, i64 %i.0 | 
|  | 88 | %tmp1 = load float, float* %arrayidx1, align 4 | 
|  | 89 | %add = fadd float %tmp, %tmp1 | 
| Johannes Doerfert | c1db67e | 2015-09-29 23:47:21 +0000 | [diff] [blame] | 90 | %arrayidx2 = getelementptr inbounds float, float* %A, i64 %i.0 | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 91 | %tmp2 = load float, float* %arrayidx2, align 4 | 
|  | 92 | %add3 = fadd float %add, %tmp2 | 
| Johannes Doerfert | c1db67e | 2015-09-29 23:47:21 +0000 | [diff] [blame] | 93 | %padd = add nsw i64 %p, %i.0 | 
|  | 94 | %arrayidx4 = getelementptr inbounds float, float* %B, i64 %padd | 
| Tobias Grosser | cdb38e5 | 2015-05-29 17:08:19 +0000 | [diff] [blame] | 95 | %tmp3 = load float, float* %arrayidx4, align 4 | 
|  | 96 | %add5 = fadd float %add3, %tmp3 | 
|  | 97 | %arrayidx6 = getelementptr inbounds float, float* %C, i64 %i.0 | 
|  | 98 | %tmp4 = load float, float* %arrayidx6, align 4 | 
|  | 99 | %add7 = fadd float %tmp4, %add5 | 
|  | 100 | store float %add7, float* %arrayidx6, align 4 | 
|  | 101 | br label %for.inc | 
|  | 102 |  | 
|  | 103 | for.inc:                                          ; preds = %for.body | 
|  | 104 | %inc = add nuw nsw i64 %i.0, 1 | 
|  | 105 | br label %for.cond | 
|  | 106 |  | 
|  | 107 | for.end:                                          ; preds = %for.cond | 
|  | 108 | ret void | 
|  | 109 | } |