1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=early-cse -earlycse-debug-hash -S < %s | FileCheck %s
3 ; RUN: opt -passes='early-cse<memssa>' -S < %s | FileCheck %s
6 declare void @use.ptr(ptr) memory(read)
8 define void @test1(float %x, float %y) {
10 ; CHECK-NEXT: [[CMP1:%.*]] = fcmp oeq float [[Y:%.*]], [[X:%.*]]
11 ; CHECK-NEXT: call void @use(i1 [[CMP1]])
12 ; CHECK-NEXT: call void @use(i1 [[CMP1]])
13 ; CHECK-NEXT: ret void
15 %cmp1 = fcmp nnan oeq float %y, %x
16 %cmp2 = fcmp oeq float %x, %y
17 call void @use(i1 %cmp1)
18 call void @use(i1 %cmp2)
22 declare void @use.i8(ptr)
24 define void @test_inbounds_program_ub_if_first_gep_poison(ptr %ptr, i64 %n) {
25 ; CHECK-LABEL: @test_inbounds_program_ub_if_first_gep_poison(
26 ; CHECK-NEXT: [[ADD_PTR_1:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i64 [[N:%.*]]
27 ; CHECK-NEXT: call void @use.i8(ptr noundef [[ADD_PTR_1]])
28 ; CHECK-NEXT: call void @use.i8(ptr [[ADD_PTR_1]])
29 ; CHECK-NEXT: ret void
31 %add.ptr.1 = getelementptr inbounds i8, ptr %ptr, i64 %n
32 call void @use.i8(ptr noundef %add.ptr.1)
33 %add.ptr.2 = getelementptr i8, ptr %ptr, i64 %n
34 call void @use.i8(ptr %add.ptr.2)
38 define void @test_inbounds_program_not_ub_if_first_gep_poison(ptr %ptr, i64 %n) {
39 ; CHECK-LABEL: @test_inbounds_program_not_ub_if_first_gep_poison(
40 ; CHECK-NEXT: [[ADD_PTR_1:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 [[N:%.*]]
41 ; CHECK-NEXT: call void @use.i8(ptr [[ADD_PTR_1]])
42 ; CHECK-NEXT: call void @use.i8(ptr [[ADD_PTR_1]])
43 ; CHECK-NEXT: ret void
45 %add.ptr.1 = getelementptr inbounds i8, ptr %ptr, i64 %n
46 call void @use.i8(ptr %add.ptr.1)
47 %add.ptr.2 = getelementptr i8, ptr %ptr, i64 %n
48 call void @use.i8(ptr %add.ptr.2)
52 define void @load_both_nonnull(ptr %p) {
53 ; CHECK-LABEL: @load_both_nonnull(
54 ; CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull [[META0:![0-9]+]]
55 ; CHECK-NEXT: call void @use.ptr(ptr [[V1]])
56 ; CHECK-NEXT: call void @use.ptr(ptr [[V1]])
57 ; CHECK-NEXT: ret void
59 %v1 = load ptr, ptr %p, !nonnull !{}
60 call void @use.ptr(ptr %v1)
61 %v2 = load ptr, ptr %p, !nonnull !{}
62 call void @use.ptr(ptr %v2)
66 define void @load_first_nonnull(ptr %p) {
67 ; CHECK-LABEL: @load_first_nonnull(
68 ; CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8
69 ; CHECK-NEXT: call void @use.ptr(ptr [[V1]])
70 ; CHECK-NEXT: call void @use.ptr(ptr [[V1]])
71 ; CHECK-NEXT: ret void
73 %v1 = load ptr, ptr %p, !nonnull !{}
74 call void @use.ptr(ptr %v1)
75 %v2 = load ptr, ptr %p
76 call void @use.ptr(ptr %v2)
80 define void @load_first_nonnull_noundef(ptr %p) {
81 ; CHECK-LABEL: @load_first_nonnull_noundef(
82 ; CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull [[META0]], !noundef [[META0]]
83 ; CHECK-NEXT: call void @use.ptr(ptr [[V1]])
84 ; CHECK-NEXT: call void @use.ptr(ptr [[V1]])
85 ; CHECK-NEXT: ret void
87 %v1 = load ptr, ptr %p, !nonnull !{}, !noundef !{}
88 call void @use.ptr(ptr %v1)
89 %v2 = load ptr, ptr %p
90 call void @use.ptr(ptr %v2)
94 define ptr @store_to_load_forward(ptr %p, ptr %p2) {
95 ; CHECK-LABEL: @store_to_load_forward(
96 ; CHECK-NEXT: [[P3:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull [[META0]]
97 ; CHECK-NEXT: store ptr [[P3]], ptr [[P2:%.*]], align 8
98 ; CHECK-NEXT: ret ptr [[P3]]
100 %p3 = load ptr, ptr %p, !nonnull !{}
101 store ptr %p3, ptr %p2
102 %res = load ptr, ptr %p2
106 define i32 @load_undef_noundef(ptr %p) {
107 ; CHECK-LABEL: @load_undef_noundef(
108 ; CHECK-NEXT: store i32 undef, ptr [[P:%.*]], align 4
109 ; CHECK-NEXT: ret i32 undef
111 store i32 undef, ptr %p
112 %v = load i32, ptr %p, !noundef !{}