test_shift_negative_constants.wat 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ;; Copyright (C) 2023 Amazon Inc. All rights reserved.
  2. ;; SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. ;;
  4. ;; Those tests verify if passing constant negative value
  5. ;; as a right parameter of the shift operator (along
  6. ;; with a constant value of the left operator) causes
  7. ;; any problems. See: https://github.com/bytecodealliance/wasm-micro-runtime/pull/2619
  8. (module
  9. (memory (export "memory") 1 1)
  10. (func $assert_eq (param i32 i32)
  11. (i32.ne (local.get 0) (local.get 1))
  12. if
  13. unreachable
  14. end
  15. )
  16. (func $i32_shr_u
  17. (call $assert_eq
  18. (i32.shr_u (i32.const -1) (i32.const -5))
  19. (i32.const 31)
  20. )
  21. )
  22. (func $i32_shr_s
  23. (call $assert_eq
  24. (i32.shr_s (i32.const 32) (i32.const -30))
  25. (i32.const 8)
  26. )
  27. )
  28. (func $i32_shl
  29. (call $assert_eq
  30. (i32.shl (i32.const -1) (i32.const -30))
  31. (i32.const -4)
  32. )
  33. )
  34. (func $const_ret (result i32)
  35. i32.const -5
  36. )
  37. ;; *_func_call tests validate the potential LLVM optimizations
  38. ;; where the right parameter of the shift operation is an
  39. ;; indirect constant value.
  40. (func $i32_shr_u_func_call
  41. (call $assert_eq
  42. (i32.shr_u (i32.const -1) (call $const_ret))
  43. (i32.const 31)
  44. )
  45. )
  46. (func $i32_shr_s_func_call
  47. (call $assert_eq
  48. (i32.shr_s
  49. (i32.const 1073741824) ;; 2^30
  50. (call $const_ret)
  51. )
  52. (i32.const 8)
  53. )
  54. )
  55. (func $i32_shl_func_call
  56. (call $assert_eq
  57. (i32.shl (i32.const -1) (call $const_ret))
  58. (i32.const -134217728)
  59. )
  60. )
  61. (func (export "_start")
  62. call $i32_shr_u
  63. call $i32_shr_s
  64. call $i32_shl
  65. call $i32_shr_u_func_call
  66. call $i32_shr_s_func_call
  67. call $i32_shl_func_call
  68. )
  69. )