signext.ll 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128:n8:16:32:64"
  3. define i32 @test1(i32 %x) {
  4. %tmp.1 = and i32 %x, 65535 ; <i32> [#uses=1]
  5. %tmp.2 = xor i32 %tmp.1, -32768 ; <i32> [#uses=1]
  6. %tmp.3 = add i32 %tmp.2, 32768 ; <i32> [#uses=1]
  7. ret i32 %tmp.3
  8. ; CHECK-LABEL: @test1(
  9. ; CHECK: %sext = shl i32 %x, 16
  10. ; CHECK: %tmp.3 = ashr exact i32 %sext, 16
  11. ; CHECK: ret i32 %tmp.3
  12. }
  13. define i32 @test2(i32 %x) {
  14. %tmp.1 = and i32 %x, 65535 ; <i32> [#uses=1]
  15. %tmp.2 = xor i32 %tmp.1, 32768 ; <i32> [#uses=1]
  16. %tmp.3 = add i32 %tmp.2, -32768 ; <i32> [#uses=1]
  17. ret i32 %tmp.3
  18. ; CHECK-LABEL: @test2(
  19. ; CHECK: %sext = shl i32 %x, 16
  20. ; CHECK: %tmp.3 = ashr exact i32 %sext, 16
  21. ; CHECK: ret i32 %tmp.3
  22. }
  23. define i32 @test3(i16 %P) {
  24. %tmp.1 = zext i16 %P to i32 ; <i32> [#uses=1]
  25. %tmp.4 = xor i32 %tmp.1, 32768 ; <i32> [#uses=1]
  26. %tmp.5 = add i32 %tmp.4, -32768 ; <i32> [#uses=1]
  27. ret i32 %tmp.5
  28. ; CHECK-LABEL: @test3(
  29. ; CHECK: %tmp.5 = sext i16 %P to i32
  30. ; CHECK: ret i32 %tmp.5
  31. }
  32. define i32 @test4(i32 %x) {
  33. %tmp.1 = and i32 %x, 255 ; <i32> [#uses=1]
  34. %tmp.2 = xor i32 %tmp.1, 128 ; <i32> [#uses=1]
  35. %tmp.3 = add i32 %tmp.2, -128 ; <i32> [#uses=1]
  36. ret i32 %tmp.3
  37. ; CHECK-LABEL: @test4(
  38. ; CHECK: %sext = shl i32 %x, 24
  39. ; CHECK: %tmp.3 = ashr exact i32 %sext, 24
  40. ; CHECK: ret i32 %tmp.3
  41. }
  42. define i32 @test5(i32 %x) {
  43. %tmp.2 = shl i32 %x, 16 ; <i32> [#uses=1]
  44. %tmp.4 = ashr i32 %tmp.2, 16 ; <i32> [#uses=1]
  45. ret i32 %tmp.4
  46. ; CHECK-LABEL: @test5(
  47. ; CHECK: %tmp.2 = shl i32 %x, 16
  48. ; CHECK: %tmp.4 = ashr exact i32 %tmp.2, 16
  49. ; CHECK: ret i32 %tmp.4
  50. }
  51. define i32 @test6(i16 %P) {
  52. %tmp.1 = zext i16 %P to i32 ; <i32> [#uses=1]
  53. %sext1 = shl i32 %tmp.1, 16 ; <i32> [#uses=1]
  54. %tmp.5 = ashr i32 %sext1, 16 ; <i32> [#uses=1]
  55. ret i32 %tmp.5
  56. ; CHECK-LABEL: @test6(
  57. ; CHECK: %tmp.5 = sext i16 %P to i32
  58. ; CHECK: ret i32 %tmp.5
  59. }
  60. define i32 @test7(i32 %x) nounwind readnone {
  61. entry:
  62. %shr = lshr i32 %x, 5 ; <i32> [#uses=1]
  63. %xor = xor i32 %shr, 67108864 ; <i32> [#uses=1]
  64. %sub = add i32 %xor, -67108864 ; <i32> [#uses=1]
  65. ret i32 %sub
  66. ; CHECK-LABEL: @test7(
  67. ; CHECK: %sub = ashr i32 %x, 5
  68. ; CHECK: ret i32 %sub
  69. }