xref: /llvm-project/llvm/test/Transforms/InstSimplify/cast.ll (revision 04b944e23050e4e0c6ee983cc9bc17740315ea4f)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
3target datalayout = "p:32:32"
4
5define i1 @test1(i1 %V) {
6; CHECK-LABEL: @test1(
7; CHECK-NEXT:  entry:
8; CHECK-NEXT:    ret i1 [[V:%.*]]
9;
10entry:
11  %Z = zext i1 %V to i32
12  %T = trunc i32 %Z to i1
13  ret i1 %T
14}
15
16define ptr @test2(ptr %V) {
17; CHECK-LABEL: @test2(
18; CHECK-NEXT:  entry:
19; CHECK-NEXT:    ret ptr [[V:%.*]]
20;
21entry:
22  ret ptr %V
23}
24
25define ptr @test3(ptr %V) {
26; CHECK-LABEL: @test3(
27; CHECK-NEXT:  entry:
28; CHECK-NEXT:    ret ptr [[V:%.*]]
29;
30entry:
31  ret ptr %V
32}
33
34define i32 @test4() {
35; CHECK-LABEL: @test4(
36; CHECK-NEXT:    ret i32 4
37;
38  %alloca = alloca i32, align 4                                     ; alloca + 0
39  %gep = getelementptr inbounds i32, ptr %alloca, i32 1            ; alloca + 4
40  %pti = ptrtoint ptr %alloca to i32                               ; alloca
41  %sub = sub i32 0, %pti                                            ; -alloca
42  %add = getelementptr [4 x i8], ptr %gep, i32 0, i32 %sub     ; alloca + 4 - alloca == 4
43  %add_to_int = ptrtoint ptr %add to i32                            ; 4
44  ret i32 %add_to_int                                               ; 4
45}
46
47define i32 @test5() {
48; CHECK-LABEL: @test5(
49; CHECK-NEXT:    ret i32 3
50;
51  %alloca = alloca i32, align 4                                     ; alloca + 0
52  %gep = getelementptr inbounds i32, ptr %alloca, i32 1            ; alloca + 4
53  %pti = ptrtoint ptr %alloca to i32                               ; alloca
54  %sub = xor i32 %pti, -1                                           ; ~alloca
55  %add = getelementptr [4 x i8], ptr %gep, i32 0, i32 %sub     ; alloca + 4 - alloca - 1 == 3
56  %add_to_int = ptrtoint ptr %add to i32                            ; 4
57  ret i32 %add_to_int                                               ; 4
58}
59