1; RUN: opt -S -instsimplify < %s | FileCheck %s
2target datalayout = "p:32:32"
3
4define i1 @test1(i1 %V) {
5entry:
6  %Z = zext i1 %V to i32
7  %T = trunc i32 %Z to i1
8  ret i1 %T
9; CHECK-LABEL: define i1 @test1(
10; CHECK: ret i1 %V
11}
12
13define i8* @test2(i8* %V) {
14entry:
15  %BC1 = bitcast i8* %V to i32*
16  %BC2 = bitcast i32* %BC1 to i8*
17  ret i8* %BC2
18; CHECK-LABEL: define i8* @test2(
19; CHECK: ret i8* %V
20}
21
22define i8* @test3(i8* %V) {
23entry:
24  %BC = bitcast i8* %V to i8*
25  ret i8* %BC
26; CHECK-LABEL: define i8* @test3(
27; CHECK: ret i8* %V
28}
29
30define i32 @test4() {
31; CHECK-LABEL: @test4(
32  %alloca = alloca i32, align 4                                     ; alloca + 0
33  %gep = getelementptr inbounds i32, i32* %alloca, i32 1            ; alloca + 4
34  %bc = bitcast i32* %gep to [4 x i8]*                              ; alloca + 4
35  %pti = ptrtoint i32* %alloca to i32                               ; alloca
36  %sub = sub i32 0, %pti                                            ; -alloca
37  %add = getelementptr [4 x i8], [4 x i8]* %bc, i32 0, i32 %sub     ; alloca + 4 - alloca == 4
38  %add_to_int = ptrtoint i8* %add to i32                            ; 4
39  ret i32 %add_to_int                                               ; 4
40; CHECK-NEXT: ret i32 4
41}
42
43define i32 @test5() {
44; CHECK-LABEL: @test5(
45  %alloca = alloca i32, align 4                                     ; alloca + 0
46  %gep = getelementptr inbounds i32, i32* %alloca, i32 1            ; alloca + 4
47  %bc = bitcast i32* %gep to [4 x i8]*                              ; alloca + 4
48  %pti = ptrtoint i32* %alloca to i32                               ; alloca
49  %sub = xor i32 %pti, -1                                           ; ~alloca
50  %add = getelementptr [4 x i8], [4 x i8]* %bc, i32 0, i32 %sub     ; alloca + 4 - alloca - 1 == 3
51  %add_to_int = ptrtoint i8* %add to i32                            ; 4
52  ret i32 %add_to_int                                               ; 4
53; CHECK-NEXT: ret i32 3
54}
55