|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 |
| 2 | + |
| 3 | +; RUN: opt -passes=instsimplify -S < %s | FileCheck %s |
| 4 | + |
| 5 | +; Test that intrinsics wasm dot call are constant folded |
| 6 | + |
| 7 | +target triple = "wasm32-unknown-unknown" |
| 8 | + |
| 9 | + |
| 10 | +define <4 x i32> @dot_zero() { |
| 11 | +; CHECK-LABEL: define <4 x i32> @dot_zero() { |
| 12 | +; CHECK-NEXT: ret <4 x i32> zeroinitializer |
| 13 | +; |
| 14 | + %res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> zeroinitializer, <8 x i16> zeroinitializer) |
| 15 | + ret <4 x i32> %res |
| 16 | +} |
| 17 | + |
| 18 | +; a = 1 2 3 4 5 6 7 8 |
| 19 | +; b = 1 2 3 4 5 6 7 8 |
| 20 | +; k1|k2 = a * b = 1 4 9 16 25 36 49 64 |
| 21 | +; k1 + k2 = (1+4) | (9 + 16) | (25 + 36) | (49 + 64) |
| 22 | +; result = 5 | 25 | 61 | 113 |
| 23 | +define <4 x i32> @dot_nonzero() { |
| 24 | +; CHECK-LABEL: define <4 x i32> @dot_nonzero() { |
| 25 | +; CHECK-NEXT: ret <4 x i32> <i32 5, i32 25, i32 61, i32 113> |
| 26 | +; |
| 27 | + %res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8>, <8 x i16> <i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8>) |
| 28 | + ret <4 x i32> %res |
| 29 | +} |
| 30 | + |
| 31 | +define <4 x i32> @dot_doubly_negative() { |
| 32 | +; CHECK-LABEL: define <4 x i32> @dot_doubly_negative() { |
| 33 | +; CHECK-NEXT: ret <4 x i32> splat (i32 2) |
| 34 | +; |
| 35 | + %res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>, <8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>) |
| 36 | + ret <4 x i32> %res |
| 37 | +} |
| 38 | + |
| 39 | +; Tests that i16 max signed values fit in i32 |
| 40 | +define <4 x i32> @dot_follow_modulo_spec_1() { |
| 41 | +; CHECK-LABEL: define <4 x i32> @dot_follow_modulo_spec_1() { |
| 42 | +; CHECK-NEXT: ret <4 x i32> <i32 2147352578, i32 0, i32 0, i32 0> |
| 43 | +; |
| 44 | + %res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 32767, i16 32767, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, <8 x i16> <i16 32767, i16 32767, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>) |
| 45 | + ret <4 x i32> %res |
| 46 | +} |
| 47 | + |
| 48 | +; Tests that i16 min signed values fit in i32 |
| 49 | +define <4 x i32> @dot_follow_modulo_spec_2() { |
| 50 | +; CHECK-LABEL: define <4 x i32> @dot_follow_modulo_spec_2() { |
| 51 | +; CHECK-NEXT: ret <4 x i32> <i32 -2147483648, i32 0, i32 0, i32 0> |
| 52 | +; |
| 53 | + %res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 -32768, i16 -32768, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, <8 x i16> <i16 -32768, i16 -32768, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>) |
| 54 | + ret <4 x i32> %res |
| 55 | +} |
| 56 | + |
0 commit comments