1 ; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -passes=indvars %s | FileCheck %s
5 ; Induction variables should not be widened for 64-bit integers,
6 ; despite being a legal type.
8 ; The cost of basic arithmetic instructions on a 64-bit integer are
9 ; twice as expensive as that on a 32-bit integer, or split into 2
12 target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"
14 ; CHECK-LABEL: @indvar_32_bit(
17 define amdgpu_kernel void @indvar_32_bit(i32 %n, ptr nocapture %output) {
19 %cmp5 = icmp sgt i32 %n, 0
20 br i1 %cmp5, label %for.body.preheader, label %for.end
22 for.body.preheader: ; preds = %entry
25 for.body: ; preds = %for.body.preheader, %for.body
26 %i.06 = phi i32 [ 0, %for.body.preheader ], [ %add, %for.body ]
27 %mul = mul nsw i32 %i.06, %i.06
28 %tmp0 = sext i32 %i.06 to i64
29 %arrayidx = getelementptr inbounds i32, ptr %output, i64 %tmp0
30 store i32 %mul, ptr %arrayidx, align 4
31 %add = add nsw i32 %i.06, 3
32 %cmp = icmp slt i32 %add, %n
33 br i1 %cmp, label %for.body, label %for.end.loopexit
35 for.end.loopexit: ; preds = %for.body
38 for.end: ; preds = %for.end.loopexit, %entry
42 ; CHECK-LABEL: @no_promote_i32(
47 ; CHECK-NOT: mul nsw i64
48 ; CHECK-NOT: add nsw i64
49 define amdgpu_kernel void @no_promote_i32(ptr addrspace(1) %out, i32 %a, i32 %b) {
54 %inc = phi i32 [ 0, %entry ], [ %inc.i, %for.body ]
55 %tmp0 = add i32 %a, %inc
56 %shl = shl i32 %inc, 8
57 %shr = ashr exact i32 %shl, 8
58 %mul = mul nsw i32 %shr, %a
59 %add = add nsw i32 %mul, %b
60 %tmp1 = sext i32 %add to i64
61 %arrayidx1 = getelementptr inbounds i32, ptr addrspace(1) %out, i64 %tmp1
62 store i32 %tmp0, ptr addrspace(1) %arrayidx1, align 4
63 %inc.i = add nsw i32 %inc, 1
64 %cmp = icmp slt i32 %inc.i, 16
65 br i1 %cmp, label %for.body, label %for.end
71 ; FIXME: This should really be promoted to i64, since it will need to
72 ; be legalized anyway.
74 ; CHECK-LABEL: @indvar_48_bit(
75 define amdgpu_kernel void @indvar_48_bit(i48 %n, ptr nocapture %output) {
77 %cmp5 = icmp sgt i48 %n, 0
78 br i1 %cmp5, label %for.body.preheader, label %for.end
80 for.body.preheader: ; preds = %entry
83 for.body: ; preds = %for.body.preheader, %for.body
84 %i.06 = phi i48 [ 0, %for.body.preheader ], [ %add, %for.body ]
85 %mul = mul nsw i48 %i.06, %i.06
86 %tmp0 = sext i48 %i.06 to i64
87 %arrayidx = getelementptr inbounds i48, ptr %output, i64 %tmp0
88 store i48 %mul, ptr %arrayidx, align 4
89 %add = add nsw i48 %i.06, 3
90 %cmp = icmp slt i48 %add, %n
91 br i1 %cmp, label %for.body, label %for.end.loopexit
93 for.end.loopexit: ; preds = %for.body
96 for.end: ; preds = %for.end.loopexit, %entry