Home | History | Annotate | Download | only in ScalarEvolution
      1 ; RUN: opt -analyze -scalar-evolution -S < %s | FileCheck %s
      2 
      3 define i16 @test1(i8 %x) {
      4   %A = zext i8 %x to i12
      5   %B = sext i12 %A to i16
      6 ; CHECK: zext i8 %x to i16
      7   ret i16 %B
      8 }
      9 
     10 define i8 @test2(i8 %x) {
     11   %A = zext i8 %x to i16
     12   %B = add i16 %A, 1025
     13   %C = trunc i16 %B to i8
     14 ; CHECK: (1 + %x)
     15   ret i8 %C
     16 }
     17 
     18 define i8 @test3(i8 %x) {
     19   %A = zext i8 %x to i16
     20   %B = mul i16 %A, 1027
     21   %C = trunc i16 %B to i8
     22 ; CHECK: (3 * %x)
     23   ret i8 %C
     24 }
     25 
     26 define void @test4(i32 %x, i32 %y) {
     27 entry:
     28   %Y = and i32 %y, 3
     29   br label %loop
     30 loop:
     31   %A = phi i32 [0, %entry], [%I, %loop]
     32   %rand1 = icmp sgt i32 %A, %Y
     33   %Z1 = select i1 %rand1, i32 %A, i32 %Y
     34   %rand2 = icmp ugt i32 %A, %Z1
     35   %Z2 = select i1 %rand2, i32 %A, i32 %Z1
     36 ; CHECK: %Z2 =
     37 ; CHECK-NEXT: -->  ([[EXPR:.*]]){{ +}}Exits: 20
     38   %B = trunc i32 %Z2 to i16
     39   %C = sext i16 %B to i30
     40 ; CHECK: %C =
     41 ; CHECK-NEXT: (trunc i32 ([[EXPR]]) to i30)
     42   %D = sext i16 %B to i32
     43 ; CHECK: %D =
     44 ; CHECK-NEXT: ([[EXPR]])
     45   %E = sext i16 %B to i34
     46 ; CHECK: %E =
     47 ; CHECK-NEXT: (zext i32 ([[EXPR]]) to i34)
     48   %F = zext i16 %B to i30
     49 ; CHECK: %F =
     50 ; CHECK-NEXT: (trunc i32 ([[EXPR]]) to i30
     51   %G = zext i16 %B to i32
     52 ; CHECK: %G =
     53 ; CHECK-NEXT: ([[EXPR]])
     54   %H = zext i16 %B to i34
     55 ; CHECK: %H =
     56 ; CHECK-NEXT: (zext i32 ([[EXPR]]) to i34)
     57   %I = add i32 %A, 1
     58   %0 = icmp ne i32 %A, 20
     59   br i1 %0, label %loop, label %exit
     60 exit:
     61   ret void
     62 }
     63 
     64 define void @test5(i32 %i) {
     65 ; CHECK-LABEL: @test5
     66   %A = and i32 %i, 1
     67 ; CHECK: -->  (zext i1 (trunc i32 %i to i1) to i32)
     68   %B = and i32 %i, 2
     69 ; CHECK: -->  (2 * (zext i1 (trunc i32 (%i /u 2) to i1) to i32))
     70   %C = and i32 %i, 63
     71 ; CHECK: -->  (zext i6 (trunc i32 %i to i6) to i32)
     72   %D = and i32 %i, 126
     73 ; CHECK: -->  (2 * (zext i6 (trunc i32 (%i /u 2) to i6) to i32))
     74   %E = and i32 %i, 64
     75 ; CHECK: -->  (64 * (zext i1 (trunc i32 (%i /u 64) to i1) to i32))
     76   %F = and i32 %i, -2147483648
     77 ; CHECK: -->  (-2147483648 * (%i /u -2147483648))
     78   ret void
     79 }
     80 
     81 define void @test6(i8 %x) {
     82 ; CHECK-LABEL: @test6
     83   %A = zext i8 %x to i16
     84   %B = shl nuw i16 %A, 8
     85   %C = and i16 %B, -2048
     86 ; CHECK: -->  (2048 * ((zext i8 %x to i16) /u 8))
     87   ret void
     88 }
     89