File: simplifycfg-options.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (124 lines) | stat: -rw-r--r-- 4,277 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -O1 -S < %s                    | FileCheck %s
; RUN: opt -passes='default<O1>' -S < %s  | FileCheck %s

; Don't simplify unconditional branches from empty blocks in simplifyCFG
; until late in the pipeline because it can destroy canonical loop structure.

define i1 @PR33605(i32 %a, i32 %b, ptr %c) {
; CHECK-LABEL: @PR33605(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[OR:%.*]] = or i32 [[B:%.*]], [[A:%.*]]
; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[C:%.*]], i64 4
; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[OR]], [[TMP0]]
; CHECK-NEXT:    br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK:       if.then:
; CHECK-NEXT:    store i32 [[OR]], ptr [[ARRAYIDX]], align 4
; CHECK-NEXT:    tail call void @foo()
; CHECK-NEXT:    br label [[IF_END]]
; CHECK:       if.end:
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[C]], align 4
; CHECK-NEXT:    [[CMP_1:%.*]] = icmp eq i32 [[OR]], [[TMP1]]
; CHECK-NEXT:    br i1 [[CMP_1]], label [[IF_END_1:%.*]], label [[IF_THEN_1:%.*]]
; CHECK:       if.then.1:
; CHECK-NEXT:    store i32 [[OR]], ptr [[C]], align 4
; CHECK-NEXT:    tail call void @foo()
; CHECK-NEXT:    br label [[IF_END_1]]
; CHECK:       if.end.1:
; CHECK-NEXT:    [[CHANGED_1_OFF0_1:%.*]] = phi i1 [ true, [[IF_THEN_1]] ], [ [[CMP]], [[IF_END]] ]
; CHECK-NEXT:    ret i1 [[CHANGED_1_OFF0_1]]
;
entry:
  br label %for.cond

for.cond:
  %i.0 = phi i32 [ 2, %entry ], [ %dec, %if.end ]
  %changed.0.off0 = phi i1 [ false, %entry ], [ %changed.1.off0, %if.end ]
  %dec = add nsw i32 %i.0, -1
  %tobool = icmp eq i32 %i.0, 0
  br i1 %tobool, label %for.cond.cleanup, label %for.body

for.cond.cleanup:
  %changed.0.off0.lcssa = phi i1 [ %changed.0.off0, %for.cond ]
  ret i1 %changed.0.off0.lcssa

for.body:
  %or = or i32 %a, %b
  %idxprom = sext i32 %dec to i64
  %arrayidx = getelementptr inbounds i32, ptr %c, i64 %idxprom
  %0 = load i32, ptr %arrayidx, align 4
  %cmp = icmp eq i32 %or, %0
  br i1 %cmp, label %if.end, label %if.then

if.then:
  store i32 %or, ptr %arrayidx, align 4
  call void @foo()
  br label %if.end

if.end:
  %changed.1.off0 = phi i1 [ true, %if.then ], [ %changed.0.off0, %for.body ]
  br label %for.cond
}

declare void @foo()

; PR34603 - https://bugs.llvm.org/show_bug.cgi?id=34603
; We should have a select of doubles, not a select of double pointers.
; SimplifyCFG should not flatten this before early-cse has a chance to eliminate redundant ops.

define double @max_of_loads(ptr %x, ptr %y, i64 %i) {
; CHECK-LABEL: @max_of_loads(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[XI_PTR:%.*]] = getelementptr double, ptr [[X:%.*]], i64 [[I:%.*]]
; CHECK-NEXT:    [[YI_PTR:%.*]] = getelementptr double, ptr [[Y:%.*]], i64 [[I]]
; CHECK-NEXT:    [[XI:%.*]] = load double, ptr [[XI_PTR]], align 8
; CHECK-NEXT:    [[YI:%.*]] = load double, ptr [[YI_PTR]], align 8
; CHECK-NEXT:    [[CMP:%.*]] = fcmp ogt double [[XI]], [[YI]]
; CHECK-NEXT:    [[XI_YI:%.*]] = select i1 [[CMP]], double [[XI]], double [[YI]]
; CHECK-NEXT:    ret double [[XI_YI]]
;
entry:
  %xi_ptr = getelementptr double, ptr %x, i64 %i
  %yi_ptr = getelementptr double, ptr %y, i64 %i
  %xi = load double, ptr %xi_ptr
  %yi = load double, ptr %yi_ptr
  %cmp = fcmp ogt double %xi, %yi
  br i1 %cmp, label %if, label %else

if:
  %xi_ptr_again = getelementptr double, ptr %x, i64 %i
  %xi_again = load double, ptr %xi_ptr_again
  br label %end

else:
  %yi_ptr_again = getelementptr double, ptr %y, i64 %i
  %yi_again = load double, ptr %yi_ptr_again
  br label %end

end:
  %max = phi double [ %xi_again,  %if ], [ %yi_again, %else ]
  ret double %max
}

define i1 @PR58313(i1 %lhs, i1 %rhs) {
; CHECK-LABEL: @PR58313(
; CHECK-NEXT:  andandend:
; CHECK-NEXT:    [[SPEC_SELECT:%.*]] = xor i1 [[LHS:%.*]], [[RHS:%.*]]
; CHECK-NEXT:    ret i1 [[SPEC_SELECT]]
;
andandend:
  %0 = xor i1 %rhs, true
  %andandval = select i1 %lhs, i1 %0, i1 false
  br i1 %andandval, label %ororend, label %oror

oror:
  %1 = xor i1 %lhs, true
  %andandval3 = select i1 %1, i1 %rhs, i1 false
  br label %ororend

ororend:
  %ororval = phi i1 [ true, %andandend ], [ %andandval3, %oror ]
  ret i1 %ororval
}