CPP_min_max.ll 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. ; RUN: opt < %s -instcombine -S | \
  2. ; RUN: grep select | not grep 'i32\*'
  3. ; This testcase corresponds to PR362, which notices that this horrible code
  4. ; is generated by the C++ front-end and LLVM optimizers, which has lots of
  5. ; loads and other stuff that are unneeded.
  6. ;
  7. ; Instcombine should propagate the load through the select instructions to
  8. ; allow elimination of the extra stuff by the mem2reg pass.
  9. define void @_Z5test1RiS_(i32* %x, i32* %y) {
  10. entry:
  11. %tmp.1.i = load i32, i32* %y ; <i32> [#uses=1]
  12. %tmp.3.i = load i32, i32* %x ; <i32> [#uses=1]
  13. %tmp.4.i = icmp slt i32 %tmp.1.i, %tmp.3.i ; <i1> [#uses=1]
  14. %retval.i = select i1 %tmp.4.i, i32* %y, i32* %x ; <i32*> [#uses=1]
  15. %tmp.4 = load i32, i32* %retval.i ; <i32> [#uses=1]
  16. store i32 %tmp.4, i32* %x
  17. ret void
  18. }
  19. define void @_Z5test2RiS_(i32* %x, i32* %y) {
  20. entry:
  21. %tmp.0 = alloca i32 ; <i32*> [#uses=2]
  22. %tmp.2 = load i32, i32* %x ; <i32> [#uses=2]
  23. store i32 %tmp.2, i32* %tmp.0
  24. %tmp.3.i = load i32, i32* %y ; <i32> [#uses=1]
  25. %tmp.4.i = icmp slt i32 %tmp.2, %tmp.3.i ; <i1> [#uses=1]
  26. %retval.i = select i1 %tmp.4.i, i32* %y, i32* %tmp.0 ; <i32*> [#uses=1]
  27. %tmp.6 = load i32, i32* %retval.i ; <i32> [#uses=1]
  28. store i32 %tmp.6, i32* %y
  29. ret void
  30. }