• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -indvars -S | FileCheck %s
2
3target triple = "nvptx64-unknown-unknown"
4
5; For the nvptx64 architecture, the cost of an arithmetic instruction on a
6; 64-bit integer is twice as expensive as that on a 32-bit integer, because the
7; hardware needs to simulate a 64-bit integer using two 32-bit integers.
8; Therefore, in this particular architecture, we should not widen induction
9; variables to 64-bit integers even though i64 is a legal type in the 64-bit
10; PTX ISA.
11
12define void @indvar_32_bit(i32 %n, i32* nocapture %output) {
13; CHECK-LABEL: @indvar_32_bit
14entry:
15  %cmp5 = icmp sgt i32 %n, 0
16  br i1 %cmp5, label %for.body.preheader, label %for.end
17
18for.body.preheader:                               ; preds = %entry
19  br label %for.body
20
21for.body:                                         ; preds = %for.body.preheader, %for.body
22  %i.06 = phi i32 [ 0, %for.body.preheader ], [ %add, %for.body ]
23; CHECK: phi i32
24  %mul = mul nsw i32 %i.06, %i.06
25  %0 = sext i32 %i.06 to i64
26  %arrayidx = getelementptr inbounds i32, i32* %output, i64 %0
27  store i32 %mul, i32* %arrayidx, align 4
28  %add = add nsw i32 %i.06, 3
29  %cmp = icmp slt i32 %add, %n
30  br i1 %cmp, label %for.body, label %for.end.loopexit
31
32for.end.loopexit:                                 ; preds = %for.body
33  br label %for.end
34
35for.end:                                          ; preds = %for.end.loopexit, %entry
36  ret void
37}
38