Skip to content

Commit d74dfac

Browse files
committed
Use SDPatternMatching and remove truncate...
Use SDPatternMatching and remove truncation. Also added 4xi64 case to reflect that.
1 parent 80e558c commit d74dfac

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/CodeGen/MachineJumpTableInfo.h"
2525
#include "llvm/CodeGen/MachineModuleInfo.h"
2626
#include "llvm/CodeGen/MachineRegisterInfo.h"
27+
#include "llvm/CodeGen/SDPatternMatch.h"
2728
#include "llvm/CodeGen/SelectionDAG.h"
2829
#include "llvm/CodeGen/SelectionDAGNodes.h"
2930
#include "llvm/IR/DiagnosticInfo.h"
@@ -37,7 +38,6 @@
3738
#include "llvm/Support/MathExtras.h"
3839
#include "llvm/Target/TargetOptions.h"
3940
using namespace llvm;
40-
4141
#define DEBUG_TYPE "wasm-lower"
4242

4343
WebAssemblyTargetLowering::WebAssemblyTargetLowering(
@@ -3243,34 +3243,29 @@ static SDValue performAnyTrueCombine(SDNode *N, SelectionDAG &DAG) {
32433243
// any_true (setcc <X>, 0, eq)
32443244
// => not (all_true X)
32453245

3246+
using namespace llvm::SDPatternMatch;
3247+
32463248
SDLoc DL(N);
32473249
assert(N->getOpcode() == ISD::INTRINSIC_WO_CHAIN);
32483250
if (N->getConstantOperandVal(0) != Intrinsic::wasm_anytrue)
32493251
return SDValue();
32503252

3251-
SDValue SetCC = N->getOperand(1);
3252-
if (SetCC.getOpcode() != ISD::SETCC)
3253+
SDValue LHS;
3254+
if (!sd_match(N->getOperand(1), m_c_SetCC(m_Value(LHS), m_Zero(),
3255+
m_SpecificCondCode(ISD::SETEQ))))
32533256
return SDValue();
32543257

3255-
SDValue LHS = SetCC->getOperand(0);
3256-
SDValue RHS = SetCC->getOperand(1);
3257-
ISD::CondCode Cond = cast<CondCodeSDNode>(SetCC->getOperand(2))->get();
32583258
EVT LT = LHS.getValueType();
32593259
unsigned NumElts = LT.getVectorNumElements();
3260-
if (NumElts != 2 && NumElts != 4 && NumElts != 8 && NumElts != 16)
3261-
return SDValue();
3262-
3263-
EVT Width = MVT::getIntegerVT(128 / NumElts);
3264-
3265-
if (!isNullOrNullSplat(RHS) || Cond != ISD::SETEQ)
3260+
if (LT.getScalarSizeInBits() > 128 / NumElts)
32663261
return SDValue();
32673262

32683263
SDValue Ret = DAG.getZExtOrTrunc(
32693264
DAG.getNode(
32703265
ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
3271-
{DAG.getConstant(Intrinsic::wasm_alltrue, DL, MVT::i32),
3272-
DAG.getSExtOrTrunc(LHS, DL, LT.changeVectorElementType(Width))}),
3266+
{DAG.getConstant(Intrinsic::wasm_alltrue, DL, MVT::i32), LHS}),
32733267
DL, MVT::i1);
3268+
32743269
Ret = DAG.getNOT(DL, Ret, MVT::i1);
32753270
return DAG.getZExtOrTrunc(Ret, DL, N->getValueType(0));
32763271
}
@@ -3437,7 +3432,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
34373432
case ISD::TRUNCATE:
34383433
return performTruncateCombine(N, DCI);
34393434
case ISD::INTRINSIC_WO_CHAIN: {
3440-
if (auto AnyTrueCombine = performAnyTrueCombine(N, DCI.DAG))
3435+
if (SDValue AnyTrueCombine = performAnyTrueCombine(N, DCI.DAG))
34413436
return AnyTrueCombine;
34423437
return performLowerPartialReduction(N, DCI.DAG);
34433438
}

llvm/test/CodeGen/WebAssembly/simd-setcc-reductions.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,26 @@ define i32 @all_true_2_i64(<2 x i64> %v) {
5757
%conv3 = zext i1 %3 to i32
5858
ret i32 %conv3
5959
}
60+
61+
62+
define i32 @all_true_4_i64(<4 x i64> %v) {
63+
; CHECK-LABEL: all_true_4_i64:
64+
; CHECK: .functype all_true_4_i64 (v128, v128) -> (i32)
65+
; CHECK-NEXT: # %bb.0:
66+
; CHECK-NEXT: v128.const $push9=, 0, 0
67+
; CHECK-NEXT: local.tee $push8=, $2=, $pop9
68+
; CHECK-NEXT: i64x2.eq $push1=, $0, $pop8
69+
; CHECK-NEXT: i64x2.eq $push0=, $1, $2
70+
; CHECK-NEXT: i8x16.shuffle $push2=, $pop1, $pop0, 0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27
71+
; CHECK-NEXT: v128.any_true $push3=, $pop2
72+
; CHECK-NEXT: i32.const $push4=, -1
73+
; CHECK-NEXT: i32.xor $push5=, $pop3, $pop4
74+
; CHECK-NEXT: i32.const $push6=, 1
75+
; CHECK-NEXT: i32.and $push7=, $pop5, $pop6
76+
; CHECK-NEXT: return $pop7
77+
%1 = icmp eq <4 x i64> %v, zeroinitializer
78+
%2 = bitcast <4 x i1> %1 to i4
79+
%3 = icmp eq i4 %2, 0
80+
%conv3 = zext i1 %3 to i32
81+
ret i32 %conv3
82+
}

0 commit comments

Comments
 (0)