sub-xor.ll 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ; RUN: opt -instcombine -S < %s | FileCheck %s
  2. define i32 @test1(i32 %x) nounwind {
  3. %and = and i32 %x, 31
  4. %sub = sub i32 63, %and
  5. ret i32 %sub
  6. ; CHECK-LABEL: @test1(
  7. ; CHECK-NEXT: and i32 %x, 31
  8. ; CHECK-NEXT: xor i32 %and, 63
  9. ; CHECK-NEXT: ret
  10. }
  11. declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
  12. define i32 @test2(i32 %x) nounwind {
  13. %count = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) nounwind readnone
  14. %sub = sub i32 31, %count
  15. ret i32 %sub
  16. ; CHECK-LABEL: @test2(
  17. ; CHECK-NEXT: ctlz
  18. ; CHECK-NEXT: xor i32 %count, 31
  19. ; CHECK-NEXT: ret
  20. }
  21. define i32 @test3(i32 %x) nounwind {
  22. %and = and i32 %x, 31
  23. %sub = xor i32 31, %and
  24. %add = add i32 %sub, 42
  25. ret i32 %add
  26. ; CHECK-LABEL: @test3(
  27. ; CHECK-NEXT: and i32 %x, 31
  28. ; CHECK-NEXT: sub nsw i32 73, %and
  29. ; CHECK-NEXT: ret
  30. }
  31. define i32 @test4(i32 %x) nounwind {
  32. %sub = xor i32 %x, 2147483648
  33. %add = add i32 %sub, 42
  34. ret i32 %add
  35. ; CHECK-LABEL: @test4(
  36. ; CHECK-NEXT: add i32 %x, -2147483606
  37. ; CHECK-NEXT: ret
  38. }