1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=newgvn -S | FileCheck %s
4 ;; Most of these are borrowed from transforms/DSE/simple.ll
5 ;; NewGVN should be able to eliminate any stores of the same value that are actually redundnat.
7 ;; tmp5 is store of the same value to the same location as the load.
8 define void @test12(ptr %x) nounwind {
9 ; CHECK-LABEL: @test12(
10 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[X:%.*]], align 4
11 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr { i32, i32 }, ptr [[X]], i32 0, i32 1
12 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr [[TMP7]], align 4
13 ; CHECK-NEXT: [[TMP17:%.*]] = sub i32 0, [[TMP8]]
14 ; CHECK-NEXT: store i32 [[TMP17]], ptr [[TMP7]], align 4
15 ; CHECK-NEXT: ret void
17 %tmp4 = getelementptr { i32, i32 }, ptr %x, i32 0, i32 0
18 %tmp5 = load i32, ptr %tmp4, align 4
19 %tmp7 = getelementptr { i32, i32 }, ptr %x, i32 0, i32 1
20 %tmp8 = load i32, ptr %tmp7, align 4
21 %tmp17 = sub i32 0, %tmp8
22 store i32 %tmp5, ptr %tmp4, align 4
23 store i32 %tmp17, ptr %tmp7, align 4
26 ; Remove redundant store if loaded value is in another block.
27 define i32 @test26(i1 %c, ptr %p) {
28 ; CHECK-LABEL: @test26(
30 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
31 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
33 ; CHECK-NEXT: br label [[BB3:%.*]]
35 ; CHECK-NEXT: br label [[BB3]]
37 ; CHECK-NEXT: ret i32 0
40 %v = load i32, ptr %p, align 4
41 br i1 %c, label %bb1, label %bb2
45 store i32 %v, ptr %p, align 4
51 declare void @unknown_func()
52 ; Remove redundant store, which is in the same loop as the load.
53 define i32 @test33(i1 %c, ptr %p, i32 %i) {
54 ; CHECK-LABEL: @test33(
56 ; CHECK-NEXT: br label [[BB1:%.*]]
58 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
59 ; CHECK-NEXT: br label [[BB2:%.*]]
61 ; CHECK-NEXT: call void @unknown_func()
62 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB3:%.*]]
64 ; CHECK-NEXT: ret i32 0
69 %v = load i32, ptr %p, align 4
72 store i32 %v, ptr %p, align 4
73 ; Might read and overwrite value at %p, but doesn't matter.
74 call void @unknown_func()
75 br i1 undef, label %bb1, label %bb3