1 ; RUN: opt -S -gvn -enable-load-pre < %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 ; These tests exercise situations when instructions that were first instructions
7 ; with implicit control flow get removed. We make sure that after that we don't
8 ; face crashes and are still able to perform PRE correctly.
10 declare i32 @foo(i32 %arg) #0
12 define hidden void @test_01(i32 %x, i32 %y) {
14 ; c2 only throws if c1 throws, so it can be safely removed and then PRE can
15 ; hoist the load out of loop.
17 ; CHECK-LABEL: @test_01
19 ; CHECK-NEXT: %c1 = call i32 @foo(i32 %x)
20 ; CHECK-NEXT: %val.pre = load i32, i32* null, align 8
21 ; CHECK-NEXT: br label %loop
23 ; CHECK-NEXT: %c3 = call i32 @foo(i32 %val.pre)
24 ; CHECK-NEXT: br label %loop
27 %c1 = call i32 @foo(i32 %x)
31 %c2 = call i32 @foo(i32 %x)
32 %val = load i32, i32* null, align 8
33 %c3 = call i32 @foo(i32 %val)
37 define hidden void @test_02(i32 %x, i32 %y) {
39 ; PRE is not allowed because c2 may throw.
41 ; CHECK-LABEL: @test_02
43 ; CHECK-NEXT: %c1 = call i32 @foo(i32 %x)
44 ; CHECK-NEXT: br label %loop
46 ; CHECK-NEXT: %c2 = call i32 @foo(i32 %y)
47 ; CHECK-NEXT: %val = load i32, i32* null, align 8
48 ; CHECK-NEXT: %c3 = call i32 @foo(i32 %val)
49 ; CHECK-NEXT: br label %loop
52 %c1 = call i32 @foo(i32 %x)
56 %c2 = call i32 @foo(i32 %y)
57 %val = load i32, i32* null, align 8
58 %c3 = call i32 @foo(i32 %val)
62 define hidden void @test_03(i32 %x, i32 %y) {
64 ; PRE of load is allowed because c2 only throws if c1 throws. c3 should
65 ; not be eliminated. c4 is eliminated because it only throws if c3 throws.
67 ; CHECK-LABEL: @test_03
69 ; CHECK-NEXT: %c1 = call i32 @foo(i32 %x)
70 ; CHECK-NEXT: %val.pre = load i32, i32* null, align 8
71 ; CHECK-NEXT: br label %loop
73 ; CHECK-NEXT: %c3 = call i32 @foo(i32 %y)
74 ; CHECK-NEXT: %c5 = call i32 @foo(i32 %val.pre)
75 ; CHECK-NEXT: br label %loop
78 %c1 = call i32 @foo(i32 %x)
82 %c2 = call i32 @foo(i32 %x)
83 %val = load i32, i32* null, align 8
84 %c3 = call i32 @foo(i32 %y)
85 %val2 = load i32, i32* null, align 8
86 %c4 = call i32 @foo(i32 %y)
87 %c5 = call i32 @foo(i32 %val)
91 define hidden void @test_04(i32 %x, i32 %y) {
93 ; PRE is not allowed even after we remove c2 because now c3 prevents us from it.
95 ; CHECK-LABEL: @test_04
97 ; CHECK-NEXT: %c1 = call i32 @foo(i32 %x)
98 ; CHECK-NEXT: br label %loop
100 ; CHECK-NEXT: %c3 = call i32 @foo(i32 %y)
101 ; CHECK-NEXT: %val = load i32, i32* null, align 8
102 ; CHECK-NEXT: %c5 = call i32 @foo(i32 %val)
103 ; CHECK-NEXT: br label %loop
106 %c1 = call i32 @foo(i32 %x)
110 %c2 = call i32 @foo(i32 %x)
111 %c3 = call i32 @foo(i32 %y)
112 %val = load i32, i32* null, align 8
113 %c4 = call i32 @foo(i32 %y)
114 %c5 = call i32 @foo(i32 %val)
118 attributes #0 = { readnone }