no-op.ll 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. ; RUN: opt < %s -reassociate -S | FileCheck %s
  2. ; When there is nothing to do, or not much to do, check that reassociate leaves
  3. ; things alone.
  4. declare void @use(i32)
  5. define void @test1(i32 %a, i32 %b) {
  6. ; Shouldn't change or move any of the add instructions. Should commute but
  7. ; otherwise not change or move any of the mul instructions.
  8. ; CHECK-LABEL: @test1(
  9. %a0 = add nsw i32 %a, 1
  10. ; CHECK-NEXT: %a0 = add nsw i32 %a, 1
  11. %m0 = mul nsw i32 3, %a
  12. ; CHECK-NEXT: %m0 = mul nsw i32 %a, 3
  13. %a1 = add nsw i32 %a0, %b
  14. ; CHECK-NEXT: %a1 = add nsw i32 %a0, %b
  15. %m1 = mul nsw i32 %b, %m0
  16. ; CHECK-NEXT: %m1 = mul nsw i32 %m0, %b
  17. call void @use(i32 %a1)
  18. ; CHECK-NEXT: call void @use
  19. call void @use(i32 %m1)
  20. ret void
  21. }
  22. define void @test2(i32 %a, i32 %b, i32 %c, i32 %d) {
  23. ; The initial add doesn't change so should not lose the nsw flag.
  24. ; CHECK-LABEL: @test2(
  25. %a0 = add nsw i32 %b, %a
  26. ; CHECK-NEXT: %a0 = add nsw i32 %b, %a
  27. %a1 = add nsw i32 %a0, %d
  28. ; CHECK-NEXT: %a1 = add i32 %a0, %c
  29. %a2 = add nsw i32 %a1, %c
  30. ; CHECK-NEXT: %a2 = add i32 %a1, %d
  31. call void @use(i32 %a2)
  32. ; CHECK-NEXT: call void @use
  33. ret void
  34. }