llvm.org GIT mirror llvm / 2dd7657
add an early out to ProcessBranchOnXOR to speed it up, handle the case when we can infer an input to the xor from all inputs that agree, instead of going into an infinite loop. Another part of PR6199 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94321 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
2 changed file(s) with 52 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
11221122 isa(BO->getOperand(1)))
11231123 return false;
11241124
1125 // If the first instruction in BB isn't a phi, we won't be able to infer
1126 // anything special about any particular predecessor.
1127 if (!isa(BB->front()))
1128 return false;
1129
11251130 // If we have a xor as the branch input to this block, and we know that the
11261131 // LHS or RHS of the xor in any predecessor is true/false, then we can clone
11271132 // the condition into the predecessor and fix that value to true, saving some
11791184 BlocksToFoldInto.push_back(XorOpValues[i].second);
11801185 }
11811186
1187 // If we inferred a value for all of the predecessors, then duplication won't
1188 // help us. However, we can just replace the LHS or RHS with the constant.
1189 if (BlocksToFoldInto.size() ==
1190 cast(BB->front()).getNumIncomingValues()) {
1191 if (SplitVal == 0) {
1192 // If all preds provide undef, just nuke the xor, because it is undef too.
1193 BO->replaceAllUsesWith(UndefValue::get(BO->getType()));
1194 BO->eraseFromParent();
1195 } else if (SplitVal->isZero()) {
1196 // If all preds provide 0, replace the xor with the other input.
1197 BO->replaceAllUsesWith(BO->getOperand(isLHS));
1198 BO->eraseFromParent();
1199 } else {
1200 // If all preds provide 1, set the computed value to 1.
1201 BO->setOperand(!isLHS, SplitVal);
1202 }
1203
1204 return true;
1205 }
1206
11821207 // Try to duplicate BB into PredBB.
11831208 return DuplicateCondBranchOnPHIIntoPred(BB, BlocksToFoldInto);
11841209 }
258258 for.body: ; preds = %for.cond
259259 br label %for.cond
260260 }
261
262 ; PR6119
263 define i32 @test9(i32 %action) nounwind {
264 entry:
265 switch i32 %action, label %lor.rhs [
266 i32 1, label %if.then
267 i32 0, label %lor.end
268 ]
269
270 if.then: ; preds = %for.cond, %lor.end, %entry
271 ret i32 undef
272
273 lor.rhs: ; preds = %entry
274 br label %lor.end
275
276 lor.end: ; preds = %lor.rhs, %entry
277 %0 = phi i1 [ undef, %lor.rhs ], [ true, %entry ] ; [#uses=1]
278 %cmp103 = xor i1 undef, %0 ; [#uses=1]
279 br i1 %cmp103, label %for.cond, label %if.then
280
281 for.cond: ; preds = %for.body, %lor.end
282 br i1 undef, label %if.then, label %for.body
283
284 for.body: ; preds = %for.cond
285 br label %for.cond
286 }
287