1; RUN: opt < %s -scalar-evolution -analyze | FileCheck %s
2
3; CHECK-LABEL: @test1
4; CHECK: -->  (zext
5; CHECK: -->  (zext
6; CHECK-NOT: -->  (zext
7
8define i32 @test1(i32 %x) {
9  %n = and i32 %x, 255
10  %y = xor i32 %n, 255
11  ret i32 %y
12}
13
14; ScalarEvolution shouldn't try to analyze %z into something like
15;   -->  (zext i4 (-1 + (-1 * (trunc i64 (8 * %x) to i4))) to i64)
16; or
17;   -->  (8 * (zext i1 (trunc i64 ((8 * %x) /u 8) to i1) to i64))
18
19; CHECK-LABEL: @test2
20; CHECK: -->  (8 * (zext i1 (trunc i64 %x to i1) to i64))
21
22define i64 @test2(i64 %x) {
23  %a = shl i64 %x, 3
24  %t = and i64 %a, 8
25  %z = xor i64 %t, 8
26  ret i64 %z
27}
28
29; Check that we transform the naive lowering of the sequence below,
30;   (4 * (zext i5 (2 * (trunc i32 %x to i5)) to i32)),
31; to
32;   (8 * (zext i4 (trunc i32 %x to i4) to i32))
33;
34; CHECK-LABEL: @test3
35define i32 @test3(i32 %x) {
36  %a = mul i32 %x, 8
37; CHECK: %b
38; CHECK-NEXT: --> (8 * (zext i4 (trunc i32 %x to i4) to i32))
39  %b = and i32 %a, 124
40  ret i32 %b
41}
42