pr21210.ll 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -instcombine -S | FileCheck %s
  2. ; Checks that the select-icmp optimization is safe in two cases
  3. declare void @foo(i32)
  4. declare i32 @bar(i32)
  5. ; don't replace 'cond' by 'len' in the home block ('bb') that
  6. ; contains the select
  7. define void @test1(i32 %len) {
  8. entry:
  9. br label %bb
  10. bb:
  11. %cmp = icmp ult i32 %len, 8
  12. %cond = select i1 %cmp, i32 %len, i32 8
  13. call void @foo(i32 %cond)
  14. %cmp11 = icmp eq i32 %cond, 8
  15. br i1 %cmp11, label %for.end, label %bb
  16. for.end:
  17. ret void
  18. ; CHECK: select
  19. ; CHECK: icmp eq i32 %cond, 8
  20. }
  21. ; don't replace 'cond' by 'len' in a block ('b1') that dominates all uses
  22. ; of the select outside the home block ('bb'), but can be reached from the home
  23. ; block on another path ('bb -> b0 -> b1')
  24. define void @test2(i32 %len) {
  25. entry:
  26. %0 = call i32 @bar(i32 %len);
  27. %cmp = icmp ult i32 %len, 4
  28. br i1 %cmp, label %bb, label %b1
  29. bb:
  30. %cond = select i1 %cmp, i32 %len, i32 8
  31. %cmp11 = icmp eq i32 %cond, 8
  32. br i1 %cmp11, label %b0, label %b1
  33. b0:
  34. call void @foo(i32 %len)
  35. br label %b1
  36. b1:
  37. ; CHECK: phi i32 [ %cond, %bb ], [ undef, %b0 ], [ %0, %entry ]
  38. %1 = phi i32 [ %cond, %bb ], [ undef, %b0 ], [ %0, %entry ]
  39. br label %ret
  40. ret:
  41. call void @foo(i32 %1)
  42. ret void
  43. }