llvm.org GIT mirror llvm / cf8b325
Fix sort predicate. qsort(3)'s predicate semantics differ from std::sort's. Fixes PR 8780. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121705 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
2 changed file(s) with 42 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
597597 static int ConstantIntSortPredicate(const void *P1, const void *P2) {
598598 const ConstantInt *LHS = *(const ConstantInt**)P1;
599599 const ConstantInt *RHS = *(const ConstantInt**)P2;
600 return LHS->getValue().ult(RHS->getValue());
600 return LHS->getValue().ult(RHS->getValue()) ? 1 : -1;
601601 }
602602
603603 /// FoldValueComparisonIntoPredecessors - The specified terminator is a value
289289 ; CHECK: ]
290290 }
291291
292
293
292 ; PR8780
293 define i32 @test11(i32 %bar) nounwind {
294 entry:
295 %cmp = icmp eq i32 %bar, 4
296 %cmp2 = icmp eq i32 %bar, 35
297 %or.cond = or i1 %cmp, %cmp2
298 %cmp5 = icmp eq i32 %bar, 53
299 %or.cond1 = or i1 %or.cond, %cmp5
300 %cmp8 = icmp eq i32 %bar, 24
301 %or.cond2 = or i1 %or.cond1, %cmp8
302 %cmp11 = icmp eq i32 %bar, 23
303 %or.cond3 = or i1 %or.cond2, %cmp11
304 %cmp14 = icmp eq i32 %bar, 55
305 %or.cond4 = or i1 %or.cond3, %cmp14
306 %cmp17 = icmp eq i32 %bar, 12
307 %or.cond5 = or i1 %or.cond4, %cmp17
308 %cmp20 = icmp eq i32 %bar, 35
309 %or.cond6 = or i1 %or.cond5, %cmp20
310 br i1 %or.cond6, label %if.then, label %if.end
311
312 if.then: ; preds = %entry
313 br label %return
314
315 if.end: ; preds = %entry
316 br label %return
317
318 return: ; preds = %if.end, %if.then
319 %retval.0 = phi i32 [ 1, %if.then ], [ 0, %if.end ]
320 ret i32 %retval.0
321
322 ; CHECK: @test11
323 ; CHECK: switch i32 %bar, label %if.end [
324 ; CHECK: i32 55, label %return
325 ; CHECK: i32 53, label %return
326 ; CHECK: i32 35, label %return
327 ; CHECK: i32 24, label %return
328 ; CHECK: i32 23, label %return
329 ; CHECK: i32 12, label %return
330 ; CHECK: i32 4, label %return
331 ; CHECK: ]
332 }