llvm.org GIT mirror llvm / 60ac719
indvars -disable-iv-rewrite: handle an edge case involving identity phis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134124 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
2 changed file(s) with 40 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
10141014 (SE->getSCEV(UseInst) != SE->getSCEV(IVOperand)))
10151015 return false;
10161016
1017 DEBUG(dbgs() << "INDVARS: Eliminated identity: " << *UseInst << '\n');
1018
10171019 UseInst->replaceAllUsesWith(IVOperand);
1018
1019 DEBUG(dbgs() << "INDVARS: Eliminated identity: " << *UseInst << '\n');
10201020 ++NumElimIdentity;
10211021 Changed = true;
10221022 DeadInsts.push_back(UseInst);
10361036
10371037 // Avoid infinite or exponential worklist processing.
10381038 // Also ensure unique worklist users.
1039 if (Simplified.insert(User))
1039 // If Def is a LoopPhi, it may not be in the Simplified set, so check for
1040 // self edges first.
1041 if (User != Def && Simplified.insert(User))
10401042 SimpleIVUsers.push_back(std::make_pair(User, Def));
10411043 }
10421044 }
11101112 // Use-def pairs if IVUsers waiting to be processed for CurrIV.
11111113 SmallVector, 8> SimpleIVUsers;
11121114
1115 // Push users of the current LoopPhi. In rare cases, pushIVUsers may be
1116 // called multiple times for the same LoopPhi. This is the proper thing to
1117 // do for loop header phis that use each other.
11131118 pushIVUsers(CurrIV, Simplified, SimpleIVUsers);
11141119
11151120 while (!SimpleIVUsers.empty()) {
2222 ; sext should be eliminated while preserving gep inboundsness.
2323 ; CHECK-NOT: sext
2424 ; CHECK: getelementptr inbounds
25 ; CHECK: exit
25 ; CHECK: exit:
2626 loop:
2727 %i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
2828 %s.01 = phi i32 [ 0, %ph ], [ %sinc, %loop ]
6363 ; CHECK: getelementptr inbounds
6464 ; %vall sext should obviously not be eliminated
6565 ; CHECK: sext
66 ; CHECK: exit
66 ; CHECK: exit:
6767 loop:
6868 %i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
6969 %s.01 = phi i64 [ 0, %ph ], [ %sinc, %loop ]
107107 ; Preserve gep inboundsness, and don't factor it.
108108 ; CHECK: getelementptr inbounds i32* %ptriv, i32 1
109109 ; CHECK-NOT: add
110 ; CHECK: exit
110 ; CHECK: exit:
111111 loop:
112112 %ptriv = phi i32* [ %first, %ph ], [ %ptrpost, %loop ]
113113 %ofs = sext i32 %idx to i64
138138 ; CHECK: phi i32
139139 ; CHECK: bitcast
140140 ; CHECK: getelementptr
141 ; CHECK: exit
141 ; CHECK: exit:
142142 loop:
143143 %iv = phi i32 [%start, %entry], [%next, %loop]
144144 %p = phi %struct* [%base, %entry], [%pinc, %loop]
156156 }
157157
158158 define void @maxvisitor(i32 %limit, i32* %base) nounwind {
159 entry: br label %loop
159 entry:
160 br label %loop
160161
161162 ; CHECK: loop:
162163 ; CHECK: phi i64
163164 ; CHECK: trunc
164 ; CHECK: exit
165 ; CHECK: exit:
165166 loop:
166167 %idx = phi i32 [ 0, %entry ], [ %idx.next, %loop.inc ]
167168 %max = phi i32 [ 0, %entry ], [ %max.next, %loop.inc ]
185186
186187 exit:
187188 ret void
188 }
189 }
190
191 ; CHECK: loop:
192 ; CHECK: phi i32
193 ; CHECK-NOT: phi
194 ; CHECK: exit:
195 define void @identityphi(i32 %limit) nounwind {
196 entry:
197 br label %loop
198
199 loop:
200 %iv = phi i32 [ 0, %entry], [ %iv.next, %control ]
201 br i1 undef, label %if.then, label %control
202
203 if.then:
204 br label %control
205
206 control:
207 %iv.next = phi i32 [ %iv, %loop ], [ undef, %if.then ]
208 %cmp = icmp slt i32 %iv.next, %limit
209 br i1 %cmp, label %loop, label %exit
210
211 exit:
212 ret void
213 }