1 ; RUN: opt -attributor --attributor-disable=false -S < %s | FileCheck %s
2 ; TODO: Add max-iteration check
3 ; ModuleID = 'value-simplify.ll'
4 source_filename = "value-simplify.ll"
5 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
8 ; Test1: Replace argument with constant
9 define internal void @test1(i32 %a) {
10 ; CHECK: tail call void @f(i32 1)
11 tail call void @f(i32 %a)
15 define void @test1_helper() {
16 tail call void @test1(i32 1)
20 ; TEST 2 : Simplify return value
21 define i32 @return0() {
25 define i32 @return1() {
29 ; CHECK: define i32 @test2_1(i1 %c)
30 define i32 @test2_1(i1 %c) {
31 br i1 %c, label %if.true, label %if.false
33 %call = tail call i32 @return0()
35 ; FIXME: %ret0 should be replaced with i32 1.
36 ; CHECK: %ret0 = add i32 0, 1
37 %ret0 = add i32 %call, 1
40 %ret1 = tail call i32 @return1()
44 ; FIXME: %ret should be replaced with i32 1.
45 ; CHECK: %ret = phi i32 [ %ret0, %if.true ], [ 1, %if.false ]
46 %ret = phi i32 [ %ret0, %if.true ], [ %ret1, %if.false ]
55 ; CHECK: define i32 @test2_2(i1 %c)
56 define i32 @test2_2(i1 %c) {
57 ; FIXME: %ret should be replaced with i32 1.
58 %ret = tail call i32 @test2_1(i1 %c)
64 declare void @use(i32)
65 ; CHECK: define void @test3(i1 %c)
66 define void @test3(i1 %c) {
67 br i1 %c, label %if.true, label %if.false
71 %ret1 = tail call i32 @return1()
75 ; CHECK: %r = phi i32 [ 1, %if.true ], [ 1, %if.false ]
76 %r = phi i32 [ 1, %if.true ], [ %ret1, %if.false ]
78 ; CHECK: tail call void @use(i32 1)
79 tail call void @use(i32 %r)
83 define void @test-select-phi(i1 %c) {
84 %select-same = select i1 %c, i32 1, i32 1
85 ; CHECK: tail call void @use(i32 1)
86 tail call void @use(i32 %select-same)
88 %select-not-same = select i1 %c, i32 1, i32 0
89 ; CHECK: tail call void @use(i32 %select-not-same)
90 tail call void @use(i32 %select-not-same)
91 br i1 %c, label %if-true, label %if-false
97 %phi-same = phi i32 [ 1, %if-true ], [ 1, %if-false ]
98 %phi-not-same = phi i32 [ 0, %if-true ], [ 1, %if-false ]
99 %phi-same-prop = phi i32 [ 1, %if-true ], [ %select-same, %if-false ]
100 %phi-same-undef = phi i32 [ 1, %if-true ], [ undef, %if-false ]
101 %select-not-same-undef = select i1 %c, i32 %phi-not-same, i32 undef
104 ; CHECK: tail call void @use(i32 1)
105 tail call void @use(i32 %phi-same)
107 ; CHECK: tail call void @use(i32 %phi-not-same)
108 tail call void @use(i32 %phi-not-same)
110 ; CHECK: tail call void @use(i32 1)
111 tail call void @use(i32 %phi-same-prop)
113 ; CHECK: tail call void @use(i32 1)
114 tail call void @use(i32 %phi-same-undef)
116 ; CHECK: tail call void @use(i32 %select-not-same-undef)
117 tail call void @use(i32 %select-not-same-undef)