Skip to content

Commit 1934453

Browse files
committed
Addresses shortcomings, add more tests
1 parent 1ae947f commit 1934453

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "WebAssemblyTargetMachine.h"
2020
#include "WebAssemblyUtilities.h"
2121
#include "llvm/CodeGen/CallingConvLower.h"
22+
#include "llvm/CodeGen/ISDOpcodes.h"
2223
#include "llvm/CodeGen/MachineFrameInfo.h"
2324
#include "llvm/CodeGen/MachineInstrBuilder.h"
2425
#include "llvm/CodeGen/MachineJumpTableInfo.h"
@@ -3394,7 +3395,13 @@ combineVectorSizedSetCCEquality(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
33943395
EVT OpVT = X.getValueType();
33953396

33963397
ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
3398+
if (!isIntEqualitySetCC(CC))
3399+
return SDValue();
3400+
33973401
SelectionDAG &DAG = DCI.DAG;
3402+
if (DCI.DAG.getMachineFunction().getFunction().hasFnAttribute(
3403+
Attribute::NoImplicitFloat))
3404+
return SDValue();
33983405
// We're looking for an oversized integer equality comparison.
33993406
if (!OpVT.isScalarInteger() || !OpVT.isByteSized() || OpVT != MVT::i128 ||
34003407
!Subtarget->hasSIMD128())
@@ -3413,7 +3420,6 @@ combineVectorSizedSetCCEquality(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
34133420

34143421
SDValue VecX = DAG.getBitcast(VecVT, X);
34153422
SDValue VecY = DAG.getBitcast(VecVT, Y);
3416-
34173423
SDValue Cmp = DAG.getSetCC(DL, VecVT, VecX, VecY, CC);
34183424

34193425
SDValue AllTrue = DAG.getNode(

llvm/test/CodeGen/WebAssembly/memcmp-expand.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ define i1 @memcmp_expand_8(ptr %a, ptr %b) {
127127
ret i1 %res
128128
}
129129

130-
; TODO: Should be using a single load i64x2 or equivalent in bitsizes
131130
define i1 @memcmp_expand_16(ptr %a, ptr %b) {
132131
; CHECK-LABEL: memcmp_expand_16:
133132
; CHECK: .functype memcmp_expand_16 (i32, i32) -> (i32)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
3+
4+
target triple = "wasm32-unknown-unknown"
5+
6+
declare i32 @memcmp(ptr, ptr, i32)
7+
8+
define i1 @setcc_load(ptr %a, ptr %b) {
9+
; CHECK-LABEL: setcc_load:
10+
; CHECK: .functype setcc_load (i32, i32) -> (i32)
11+
; CHECK-NEXT: # %bb.0:
12+
; CHECK-NEXT: v128.load $push1=, 0($0):p2align=0
13+
; CHECK-NEXT: v128.load $push0=, 0($1):p2align=0
14+
; CHECK-NEXT: i8x16.eq $push2=, $pop1, $pop0
15+
; CHECK-NEXT: i8x16.all_true $push3=, $pop2
16+
; CHECK-NEXT: i32.eqz $push4=, $pop3
17+
; CHECK-NEXT: return $pop4
18+
%cmp_16 = call i32 @memcmp(ptr %a, ptr %b, i32 16)
19+
%res = icmp eq i32 %cmp_16, 0
20+
ret i1 %res
21+
}
22+
23+
; INFO: Negative test: noimplicitfloat disables simd
24+
define i1 @setcc_load_should_not_vectorize(ptr %a, ptr %b) noimplicitfloat {
25+
; CHECK-LABEL: setcc_load_should_not_vectorize:
26+
; CHECK: .functype setcc_load_should_not_vectorize (i32, i32) -> (i32)
27+
; CHECK-NEXT: # %bb.0:
28+
; CHECK-NEXT: i64.load $push4=, 0($0):p2align=0
29+
; CHECK-NEXT: i64.load $push3=, 0($1):p2align=0
30+
; CHECK-NEXT: i64.xor $push5=, $pop4, $pop3
31+
; CHECK-NEXT: i64.load $push1=, 8($0):p2align=0
32+
; CHECK-NEXT: i64.load $push0=, 8($1):p2align=0
33+
; CHECK-NEXT: i64.xor $push2=, $pop1, $pop0
34+
; CHECK-NEXT: i64.or $push6=, $pop5, $pop2
35+
; CHECK-NEXT: i64.eqz $push7=, $pop6
36+
; CHECK-NEXT: return $pop7
37+
%cmp_16 = call i32 @memcmp(ptr %a, ptr %b, i32 16)
38+
%res = icmp eq i32 %cmp_16, 0
39+
ret i1 %res
40+
}
41+
42+
define i1 @setcc_eq_const_i128(ptr %ptr) {
43+
; CHECK-LABEL: setcc_eq_const_i128:
44+
; CHECK: .functype setcc_eq_const_i128 (i32) -> (i32)
45+
; CHECK-NEXT: # %bb.0:
46+
; CHECK-NEXT: v128.load $push0=, 0($0)
47+
; CHECK-NEXT: v128.const $push1=, 6, 0
48+
; CHECK-NEXT: i8x16.eq $push2=, $pop0, $pop1
49+
; CHECK-NEXT: i8x16.all_true $push3=, $pop2
50+
; CHECK-NEXT: i32.eqz $push4=, $pop3
51+
; CHECK-NEXT: return $pop4
52+
%l = load i128, ptr %ptr
53+
%res = icmp eq i128 %l, 6
54+
ret i1 %res
55+
}
56+
57+
define i1 @setcc_ne_const_i128(ptr %ptr) {
58+
; CHECK-LABEL: setcc_ne_const_i128:
59+
; CHECK: .functype setcc_ne_const_i128 (i32) -> (i32)
60+
; CHECK-NEXT: # %bb.0:
61+
; CHECK-NEXT: v128.load $push0=, 0($0)
62+
; CHECK-NEXT: v128.const $push1=, 16, 0
63+
; CHECK-NEXT: i8x16.ne $push2=, $pop0, $pop1
64+
; CHECK-NEXT: i8x16.all_true $push3=, $pop2
65+
; CHECK-NEXT: return $pop3
66+
%l = load i128, ptr %ptr
67+
%res = icmp ne i128 %l, 16
68+
ret i1 %res
69+
}
70+
71+
; INFO: Negative test: only eq and ne works
72+
define i1 @setcc_slt_const_i128(ptr %ptr) {
73+
; CHECK-LABEL: setcc_slt_const_i128:
74+
; CHECK: .functype setcc_slt_const_i128 (i32) -> (i32)
75+
; CHECK-NEXT: # %bb.0:
76+
; CHECK-NEXT: i64.load $push2=, 0($0)
77+
; CHECK-NEXT: i64.const $push3=, 25
78+
; CHECK-NEXT: i64.lt_u $push4=, $pop2, $pop3
79+
; CHECK-NEXT: i64.load $push8=, 8($0)
80+
; CHECK-NEXT: local.tee $push7=, $1=, $pop8
81+
; CHECK-NEXT: i64.const $push0=, 0
82+
; CHECK-NEXT: i64.lt_s $push1=, $pop7, $pop0
83+
; CHECK-NEXT: i64.eqz $push5=, $1
84+
; CHECK-NEXT: i32.select $push6=, $pop4, $pop1, $pop5
85+
; CHECK-NEXT: return $pop6
86+
%l = load i128, ptr %ptr
87+
%res = icmp slt i128 %l, 25
88+
ret i1 %res
89+
}

0 commit comments

Comments
 (0)