1; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s 2 3target 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" 4 5; Indvars should be able to fold IV increments into shr when low bits are zero. 6; 7; CHECK: @foldIncShr 8; CHECK: shr.1 = lshr i32 %0, 5 9define i32 @foldIncShr(i32* %bitmap, i32 %bit_addr, i32 %nbits) nounwind { 10entry: 11 br label %while.body 12 13while.body: 14 %0 = phi i32 [ 0, %entry ], [ %inc.2, %while.body ] 15 %shr = lshr i32 %0, 5 16 %arrayidx = getelementptr inbounds i32* %bitmap, i32 %shr 17 %tmp6 = load i32* %arrayidx, align 4 18 %inc.1 = add i32 %0, 1 19 %shr.1 = lshr i32 %inc.1, 5 20 %arrayidx.1 = getelementptr inbounds i32* %bitmap, i32 %shr.1 21 %tmp6.1 = load i32* %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 25 26while.end: 27 %r = add i32 %tmp6, %tmp6.1 28 ret i32 %r 29} 30 31; Invdars should not fold an increment into shr unless 2^shiftBits is 32; a multiple of the recurrence step. 33; 34; CHECK: @noFoldIncShr 35; CHECK: shr.1 = lshr i32 %inc.1, 5 36define i32 @noFoldIncShr(i32* %bitmap, i32 %bit_addr, i32 %nbits) nounwind { 37entry: 38 br label %while.body 39 40while.body: 41 %0 = phi i32 [ 0, %entry ], [ %inc.3, %while.body ] 42 %shr = lshr i32 %0, 5 43 %arrayidx = getelementptr inbounds i32* %bitmap, i32 %shr 44 %tmp6 = load i32* %arrayidx, align 4 45 %inc.1 = add i32 %0, 1 46 %shr.1 = lshr i32 %inc.1, 5 47 %arrayidx.1 = getelementptr inbounds i32* %bitmap, i32 %shr.1 48 %tmp6.1 = load i32* %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 52 53while.end: 54 %r = add i32 %tmp6, %tmp6.1 55 ret i32 %r 56} 57