Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 2 additions & 52 deletions llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3383,65 +3383,15 @@ static SDValue TryMatchTrue(SDNode *N, EVT VecVT, SelectionDAG &DAG) {
return DAG.getZExtOrTrunc(Ret, DL, N->getValueType(0));
}

/// Try to convert a i128 comparison to a v16i8 comparison before type
/// legalization splits it up into chunks
static SDValue
combineVectorSizedSetCCEquality(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
const WebAssemblySubtarget *Subtarget) {

SDLoc DL(N);
SDValue X = N->getOperand(0);
SDValue Y = N->getOperand(1);
EVT VT = N->getValueType(0);
EVT OpVT = X.getValueType();

SelectionDAG &DAG = DCI.DAG;
if (DCI.DAG.getMachineFunction().getFunction().hasFnAttribute(
Attribute::NoImplicitFloat))
return SDValue();

ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
// We're looking for an oversized integer equality comparison with SIMD
if (!OpVT.isScalarInteger() || !OpVT.isByteSized() || OpVT != MVT::i128 ||
!Subtarget->hasSIMD128() || !isIntEqualitySetCC(CC))
return SDValue();

// Don't perform this combine if constructing the vector will be expensive.
auto IsVectorBitCastCheap = [](SDValue X) {
X = peekThroughBitcasts(X);
return isa<ConstantSDNode>(X) || X.getOpcode() == ISD::LOAD;
};

if (!IsVectorBitCastCheap(X) || !IsVectorBitCastCheap(Y))
return SDValue();

SDValue VecX = DAG.getBitcast(MVT::v16i8, X);
SDValue VecY = DAG.getBitcast(MVT::v16i8, Y);
SDValue Cmp = DAG.getSetCC(DL, MVT::v16i8, VecX, VecY, CC);

SDValue Intr =
DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
{DAG.getConstant(CC == ISD::SETEQ ? Intrinsic::wasm_alltrue
: Intrinsic::wasm_anytrue,
DL, MVT::i32),
Cmp});

return DAG.getSetCC(DL, VT, Intr, DAG.getConstant(0, DL, MVT::i32), CC);
}

static SDValue performSETCCCombine(SDNode *N,
TargetLowering::DAGCombinerInfo &DCI,
const WebAssemblySubtarget *Subtarget) {
TargetLowering::DAGCombinerInfo &DCI) {
if (!DCI.isBeforeLegalize())
return SDValue();

EVT VT = N->getValueType(0);
if (!VT.isScalarInteger())
return SDValue();

if (SDValue V = combineVectorSizedSetCCEquality(N, DCI, Subtarget))
return V;

SDValue LHS = N->getOperand(0);
if (LHS->getOpcode() != ISD::BITCAST)
return SDValue();
Expand Down Expand Up @@ -3621,7 +3571,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
case ISD::BITCAST:
return performBitcastCombine(N, DCI);
case ISD::SETCC:
return performSETCCCombine(N, DCI, Subtarget);
return performSETCCCombine(N, DCI);
case ISD::VECTOR_SHUFFLE:
return performVECTOR_SHUFFLECombine(N, DCI);
case ISD::SIGN_EXTEND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ WebAssemblyTTIImpl::enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const {

Options.AllowOverlappingLoads = true;

if (ST->hasSIMD128())
Options.LoadSizes.push_back(16);
// TODO: Teach WebAssembly backend about load v128.

Options.LoadSizes.append({8, 4, 2, 1});
Options.MaxNumLoads = TLI->getMaxExpandSizeMemcmp(OptSize);
Expand Down
22 changes: 15 additions & 7 deletions llvm/test/CodeGen/WebAssembly/memcmp-expand.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
; RUN: llc < %s -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s

target triple = "wasm32-unknown-unknown"

Expand Down Expand Up @@ -127,16 +127,24 @@ define i1 @memcmp_expand_8(ptr %a, ptr %b) {
ret i1 %res
}

; TODO: Should be using a single load i64x2 or equivalent in bitsizes
define i1 @memcmp_expand_16(ptr %a, ptr %b) {
; CHECK-LABEL: memcmp_expand_16:
; CHECK: .functype memcmp_expand_16 (i32, i32) -> (i32)
; CHECK-NEXT: # %bb.0:
; CHECK-NEXT: v128.load $push1=, 0($0):p2align=0
; CHECK-NEXT: v128.load $push0=, 0($1):p2align=0
; CHECK-NEXT: i8x16.eq $push2=, $pop1, $pop0
; CHECK-NEXT: i8x16.all_true $push3=, $pop2
; CHECK-NEXT: i32.eqz $push4=, $pop3
; CHECK-NEXT: return $pop4
; CHECK-NEXT: i64.load $push7=, 0($0):p2align=0
; CHECK-NEXT: i64.load $push6=, 0($1):p2align=0
; CHECK-NEXT: i64.xor $push8=, $pop7, $pop6
; CHECK-NEXT: i32.const $push0=, 8
; CHECK-NEXT: i32.add $push3=, $0, $pop0
; CHECK-NEXT: i64.load $push4=, 0($pop3):p2align=0
; CHECK-NEXT: i32.const $push11=, 8
; CHECK-NEXT: i32.add $push1=, $1, $pop11
; CHECK-NEXT: i64.load $push2=, 0($pop1):p2align=0
; CHECK-NEXT: i64.xor $push5=, $pop4, $pop2
; CHECK-NEXT: i64.or $push9=, $pop8, $pop5
; CHECK-NEXT: i64.eqz $push10=, $pop9
; CHECK-NEXT: return $pop10
%cmp_16 = call i32 @memcmp(ptr %a, ptr %b, i32 16)
%res = icmp eq i32 %cmp_16, 0
ret i1 %res
Expand Down
89 changes: 0 additions & 89 deletions llvm/test/CodeGen/WebAssembly/simd-setcc.ll

This file was deleted.