preserve-sminmax.ll 857 B

1234567891011121314151617181920212223242526272829303132
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. ; Instcombine normally would fold the sdiv into the comparison,
  3. ; making "icmp slt i32 %h, 2", but in this case the sdiv has
  4. ; another use, so it wouldn't a big win, and it would also
  5. ; obfuscate an otherise obvious smax pattern to the point where
  6. ; other analyses wouldn't recognize it.
  7. define i32 @foo(i32 %h) {
  8. %sd = sdiv i32 %h, 2
  9. %t = icmp slt i32 %sd, 1
  10. %r = select i1 %t, i32 %sd, i32 1
  11. ret i32 %r
  12. }
  13. ; CHECK: %sd = sdiv i32 %h, 2
  14. ; CHECK: %t = icmp slt i32 %sd, 1
  15. ; CHECK: %r = select i1 %t, i32 %sd, i32 1
  16. ; CHECK: ret i32 %r
  17. define i32 @bar(i32 %h) {
  18. %sd = sdiv i32 %h, 2
  19. %t = icmp sgt i32 %sd, 1
  20. %r = select i1 %t, i32 %sd, i32 1
  21. ret i32 %r
  22. }
  23. ; CHECK: %sd = sdiv i32 %h, 2
  24. ; CHECK: %t = icmp sgt i32 %sd, 1
  25. ; CHECK: %r = select i1 %t, i32 %sd, i32 1
  26. ; CHECK: ret i32 %r