1; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -indvars %s | FileCheck %s 2 3; Bug 21148 4 5; Induction variables should not be widened for 64-bit integers, 6; despite being a legal type. 7; 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 10; 32-bit components. 11 12target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-p24:64:64-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64" 13 14; CHECK-LABEL: @indvar_32_bit( 15; CHECK-NOT: sext i32 16; CHECK: phi i32 17define void @indvar_32_bit(i32 %n, i32* nocapture %output) { 18entry: 19 %cmp5 = icmp sgt i32 %n, 0 20 br i1 %cmp5, label %for.body.preheader, label %for.end 21 22for.body.preheader: ; preds = %entry 23 br label %for.body 24 25for.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, i32* %output, i64 %tmp0 30 store i32 %mul, i32* %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 34 35for.end.loopexit: ; preds = %for.body 36 br label %for.end 37 38for.end: ; preds = %for.end.loopexit, %entry 39 ret void 40} 41 42; CHECK-LABEL: @no_promote_i32( 43; CHECK-NOT: sext i32 44; CHECK: br 45; CHECK-NOT: shl i64 46; CHECK-NOT: ashr i64 47; CHECK-NOT: mul nsw i64 48; CHECK-NOT: add nsw i64 49define void @no_promote_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) { 50entry: 51 br label %for.body 52 53for.body: 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, i32 addrspace(1)* %out, i64 %tmp1 62 store i32 %tmp0, i32 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 66 67for.end: 68 ret void 69} 70 71; FIXME: This should really be promoted to i64, since it will need to 72; be legalized anyway. 73 74; CHECK-LABEL: @indvar_48_bit( 75define void @indvar_48_bit(i48 %n, i48* nocapture %output) { 76entry: 77 %cmp5 = icmp sgt i48 %n, 0 78 br i1 %cmp5, label %for.body.preheader, label %for.end 79 80for.body.preheader: ; preds = %entry 81 br label %for.body 82 83for.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, i48* %output, i64 %tmp0 88 store i48 %mul, i48* %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 92 93for.end.loopexit: ; preds = %for.body 94 br label %for.end 95 96for.end: ; preds = %for.end.loopexit, %entry 97 ret void 98} 99