llvm.org GIT mirror llvm / 6e0ce24
indvars -disable-iv-rewrite: handle cloning binary operators that cannot overflow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134177 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
2 changed file(s) with 45 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
658658 LHS, RHS,
659659 NarrowBO->getName());
660660 Builder.Insert(WideBO);
661 if (NarrowBO->hasNoUnsignedWrap()) WideBO->setHasNoUnsignedWrap();
662 if (NarrowBO->hasNoSignedWrap()) WideBO->setHasNoSignedWrap();
663
661 if (const OverflowingBinaryOperator *OBO =
662 dyn_cast(NarrowBO)) {
663 if (OBO->hasNoUnsignedWrap()) WideBO->setHasNoUnsignedWrap();
664 if (OBO->hasNoSignedWrap()) WideBO->setHasNoSignedWrap();
665 }
664666 return WideBO;
665667 }
666668 llvm_unreachable(0);
11201122 while (!SimpleIVUsers.empty()) {
11211123 Instruction *UseInst, *Operand;
11221124 tie(UseInst, Operand) = SimpleIVUsers.pop_back_val();
1125 // Bypass back edges to avoid extra work.
1126 if (UseInst == CurrIV) continue;
11231127
11241128 if (EliminateIVUser(UseInst, Operand)) {
11251129 pushIVUsers(Operand, Simplified, SimpleIVUsers);
159159 entry:
160160 br label %loop
161161
162 ; Test inserting a truncate at a phi use.
163 ;
162164 ; CHECK: loop:
163165 ; CHECK: phi i64
164166 ; CHECK: trunc
188190 ret void
189191 }
190192
193 define void @identityphi(i32 %limit) nounwind {
194 entry:
195 br label %loop
196
197 ; Test an edge case of removing an identity phi that directly feeds
198 ; back to the loop iv.
199 ;
191200 ; CHECK: loop:
192201 ; CHECK: phi i32
193202 ; CHECK-NOT: phi
194203 ; CHECK: exit:
195 define void @identityphi(i32 %limit) nounwind {
196 entry:
197 br label %loop
198
199204 loop:
200205 %iv = phi i32 [ 0, %entry], [ %iv.next, %control ]
201206 br i1 undef, label %if.then, label %control
211216 exit:
212217 ret void
213218 }
219
220 define i64 @cloneOr(i32 %limit, i64* %base) nounwind {
221 entry:
222 ; ensure that the loop can't overflow
223 %halfLim = ashr i32 %limit, 2
224 br label %loop
225
226 ; Test cloning an or, which is not an OverflowBinaryOperator.
227 ;
228 ; CHECK: loop:
229 ; CHECK: phi i64
230 ; CHECK-NOT: sext
231 ; CHECK: or i64
232 ; CHECK: exit:
233 loop:
234 %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
235 %t1 = sext i32 %iv to i64
236 %adr = getelementptr i64* %base, i64 %t1
237 %val = load i64* %adr
238 %t2 = or i32 %iv, 1
239 %t3 = sext i32 %t2 to i64
240 %iv.next = add i32 %iv, 2
241 %cmp = icmp slt i32 %iv.next, %halfLim
242 br i1 %cmp, label %loop, label %exit
243
244 exit:
245 %result = and i64 %val, %t3
246 ret i64 %result
247 }