idioms.ll 681 B

1234567891011121314151617181920212223242526272829303132
  1. ; RUN: opt -instcombine -S < %s | FileCheck %s
  2. ; Check that code corresponding to the following C function is
  3. ; simplified into a single ASR operation:
  4. ;
  5. ; int test_asr(int a, int b) {
  6. ; return a < 0 ? -(-a - 1 >> b) - 1 : a >> b;
  7. ; }
  8. ;
  9. define i32 @test_asr(i32 %a, i32 %b) {
  10. entry:
  11. %c = icmp slt i32 %a, 0
  12. br i1 %c, label %bb2, label %bb3
  13. bb2:
  14. %t1 = sub i32 0, %a
  15. %not = sub i32 %t1, 1
  16. %d = ashr i32 %not, %b
  17. %t2 = sub i32 0, %d
  18. %not2 = sub i32 %t2, 1
  19. br label %bb4
  20. bb3:
  21. %e = ashr i32 %a, %b
  22. br label %bb4
  23. bb4:
  24. %f = phi i32 [ %not2, %bb2 ], [ %e, %bb3 ]
  25. ret i32 %f
  26. ; CHECK-LABEL: @test_asr(
  27. ; CHECK: bb4:
  28. ; CHECK: %f = ashr i32 %a, %b
  29. ; CHECK: ret i32 %f
  30. }