1 ; RUN: opt < %s -passes=indvars -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n32:64"
5 ; Indvars should be able to fold IV increments into shr when low bits are zero.
7 ; CHECK-LABEL: @foldIncShr(
8 ; CHECK: shr.1 = lshr i32 %0, 5
9 define i32 @foldIncShr(ptr %bitmap, i32 %bit_addr, i32 %nbits) nounwind {
14 %0 = phi i32 [ 0, %entry ], [ %inc.2, %while.body ]
16 %arrayidx = getelementptr inbounds i32, ptr %bitmap, i32 %shr
17 %tmp6 = load i32, ptr %arrayidx, align 4
18 %inc.1 = add i32 %0, 1
19 %shr.1 = lshr i32 %inc.1, 5
20 %arrayidx.1 = getelementptr inbounds i32, ptr %bitmap, i32 %shr.1
21 %tmp6.1 = load i32, ptr %arrayidx.1, align 4
22 %inc.2 = add i32 %inc.1, 1
23 %exitcond.3 = icmp eq i32 %inc.2, 128
24 br i1 %exitcond.3, label %while.end, label %while.body
27 %r = add i32 %tmp6, %tmp6.1
31 ; Invdars should not fold an increment into shr unless 2^shiftBits is
32 ; a multiple of the recurrence step.
34 ; CHECK-LABEL: @noFoldIncShr(
35 ; CHECK: shr.1 = lshr i32 %inc.1, 5
36 define i32 @noFoldIncShr(ptr %bitmap, i32 %bit_addr, i32 %nbits) nounwind {
41 %0 = phi i32 [ 0, %entry ], [ %inc.3, %while.body ]
43 %arrayidx = getelementptr inbounds i32, ptr %bitmap, i32 %shr
44 %tmp6 = load i32, ptr %arrayidx, align 4
45 %inc.1 = add i32 %0, 1
46 %shr.1 = lshr i32 %inc.1, 5
47 %arrayidx.1 = getelementptr inbounds i32, ptr %bitmap, i32 %shr.1
48 %tmp6.1 = load i32, ptr %arrayidx.1, align 4
49 %inc.3 = add i32 %inc.1, 2
50 %exitcond.3 = icmp eq i32 %inc.3, 96
51 br i1 %exitcond.3, label %while.end, label %while.body
54 %r = add i32 %tmp6, %tmp6.1