Home | History | Annotate | Download | only in IndVarSimplify
      1 ; RUN: opt < %s -indvars -S | FileCheck %s
      2 ;
      3 ; PR1301
      4 
      5 ; Do a bunch of analysis and prove that the loops can use an i32 trip
      6 ; count without casting.
      7 ;
      8 ; Note that all four functions should actually be converted to
      9 ; memset. However, this test case validates indvars behavior.  We
     10 ; don't check that phis are "folded together" because that is a job
     11 ; for loop strength reduction. But indvars must remove sext, zext, and add i8.
     12 ;
     13 
     14 ; ModuleID = 'ada.bc'
     15 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32"
     16 target triple = "i686-pc-linux-gnu"
     17 
     18 ; CHECK-LABEL: @kinds__sbytezero
     19 ; CHECK:         bb.thread:
     20 ; CHECK:         sext
     21 ; CHECK:         bb:
     22 ; CHECK-NOT:     {{sext i8|zext i8|add i8|trunc}}
     23 
     24 define void @kinds__sbytezero([256 x i32]* nocapture %a) nounwind {
     25 bb.thread:
     26 	%tmp46 = getelementptr [256 x i32], [256 x i32]* %a, i32 0, i32 0		; <i32*> [#uses=1]
     27 	store i32 0, i32* %tmp46
     28 	br label %bb
     29 
     30 bb:		; preds = %bb, %bb.thread
     31 	%i.0.reg2mem.0 = phi i8 [ -128, %bb.thread ], [ %tmp8, %bb ]		; <i8> [#uses=1]
     32 	%tmp8 = add i8 %i.0.reg2mem.0, 1		; <i8> [#uses=3]
     33 	%tmp1 = sext i8 %tmp8 to i32		; <i32> [#uses=1]
     34 	%tmp3 = add i32 %tmp1, 128		; <i32> [#uses=1]
     35 	%tmp4 = getelementptr [256 x i32], [256 x i32]* %a, i32 0, i32 %tmp3		; <i32*> [#uses=1]
     36 	store i32 0, i32* %tmp4
     37 	%0 = icmp eq i8 %tmp8, 127		; <i1> [#uses=1]
     38 	br i1 %0, label %return, label %bb
     39 
     40 return:		; preds = %bb
     41 	ret void
     42 }
     43 
     44 ; CHECK-LABEL: @kinds__ubytezero
     45 
     46 define void @kinds__ubytezero([256 x i32]* nocapture %a) nounwind {
     47 bb.thread:
     48 	%tmp35 = getelementptr [256 x i32], [256 x i32]* %a, i32 0, i32 0		; <i32*> [#uses=1]
     49 	store i32 0, i32* %tmp35
     50 	br label %bb
     51 
     52 bb:		; preds = %bb, %bb.thread
     53 	%i.0.reg2mem.0 = phi i8 [ 0, %bb.thread ], [ %tmp7, %bb ]		; <i8> [#uses=1]
     54 	%tmp7 = add i8 %i.0.reg2mem.0, 1		; <i8> [#uses=3]
     55 	%tmp1 = zext i8 %tmp7 to i32		; <i32> [#uses=1]
     56 	%tmp3 = getelementptr [256 x i32], [256 x i32]* %a, i32 0, i32 %tmp1		; <i32*> [#uses=1]
     57 	store i32 0, i32* %tmp3
     58 	%0 = icmp eq i8 %tmp7, -1		; <i1> [#uses=1]
     59 	br i1 %0, label %return, label %bb
     60 
     61 return:		; preds = %bb
     62 	ret void
     63 }
     64 
     65 define void @kinds__srangezero([21 x i32]* nocapture %a) nounwind {
     66 bb.thread:
     67 	br label %bb
     68 
     69 bb:		; preds = %bb, %bb.thread
     70 	%i.0.reg2mem.0 = phi i8 [ -10, %bb.thread ], [ %tmp7, %bb ]		; <i8> [#uses=2]
     71 	%tmp12 = sext i8 %i.0.reg2mem.0 to i32		; <i32> [#uses=1]
     72 	%tmp4 = add i32 %tmp12, 10		; <i32> [#uses=1]
     73 	%tmp5 = getelementptr [21 x i32], [21 x i32]* %a, i32 0, i32 %tmp4		; <i32*> [#uses=1]
     74 	store i32 0, i32* %tmp5
     75 	%tmp7 = add i8 %i.0.reg2mem.0, 1		; <i8> [#uses=2]
     76 	%0 = icmp sgt i8 %tmp7, 10		; <i1> [#uses=1]
     77 	br i1 %0, label %return, label %bb
     78 
     79 return:		; preds = %bb
     80 	ret void
     81 }
     82 
     83 define void @kinds__urangezero([21 x i32]* nocapture %a) nounwind {
     84 bb.thread:
     85 	br label %bb
     86 
     87 bb:		; preds = %bb, %bb.thread
     88 	%i.0.reg2mem.0 = phi i8 [ 10, %bb.thread ], [ %tmp7, %bb ]		; <i8> [#uses=2]
     89 	%tmp12 = sext i8 %i.0.reg2mem.0 to i32		; <i32> [#uses=1]
     90 	%tmp4 = add i32 %tmp12, -10		; <i32> [#uses=1]
     91 	%tmp5 = getelementptr [21 x i32], [21 x i32]* %a, i32 0, i32 %tmp4		; <i32*> [#uses=1]
     92 	store i32 0, i32* %tmp5
     93 	%tmp7 = add i8 %i.0.reg2mem.0, 1		; <i8> [#uses=2]
     94 	%0 = icmp sgt i8 %tmp7, 30		; <i1> [#uses=1]
     95 	br i1 %0, label %return, label %bb
     96 
     97 return:		; preds = %bb
     98 	ret void
     99 }
    100