Skip to content

Commit a1977d2

Browse files
committed
Use SDPatternMatching and remove truncate
1 parent 80e558c commit a1977d2

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 10 additions & 13 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"
@@ -35,9 +36,10 @@
3536
#include "llvm/Support/ErrorHandling.h"
3637
#include "llvm/Support/KnownBits.h"
3738
#include "llvm/Support/MathExtras.h"
39+
#include "llvm/Support/raw_ostream.h"
3840
#include "llvm/Target/TargetOptions.h"
3941
using namespace llvm;
40-
42+
using namespace llvm::SDPatternMatch;
4143
#define DEBUG_TYPE "wasm-lower"
4244

4345
WebAssemblyTargetLowering::WebAssemblyTargetLowering(
@@ -3248,29 +3250,24 @@ static SDValue performAnyTrueCombine(SDNode *N, SelectionDAG &DAG) {
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)
3260+
if (LT.getScalarSizeInBits() > 128 / NumElts)
32613261
return SDValue();
32623262

32633263
EVT Width = MVT::getIntegerVT(128 / NumElts);
32643264

3265-
if (!isNullOrNullSplat(RHS) || Cond != ISD::SETEQ)
3266-
return SDValue();
3267-
32683265
SDValue Ret = DAG.getZExtOrTrunc(
32693266
DAG.getNode(
32703267
ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
3271-
{DAG.getConstant(Intrinsic::wasm_alltrue, DL, MVT::i32),
3272-
DAG.getSExtOrTrunc(LHS, DL, LT.changeVectorElementType(Width))}),
3268+
{DAG.getConstant(Intrinsic::wasm_alltrue, DL, MVT::i32), LHS}),
32733269
DL, MVT::i1);
3270+
32743271
Ret = DAG.getNOT(DL, Ret, MVT::i1);
32753272
return DAG.getZExtOrTrunc(Ret, DL, N->getValueType(0));
32763273
}
@@ -3437,7 +3434,7 @@ WebAssemblyTargetLowering::PerformDAGCombine(SDNode *N,
34373434
case ISD::TRUNCATE:
34383435
return performTruncateCombine(N, DCI);
34393436
case ISD::INTRINSIC_WO_CHAIN: {
3440-
if (auto AnyTrueCombine = performAnyTrueCombine(N, DCI.DAG))
3437+
if (SDValue AnyTrueCombine = performAnyTrueCombine(N, DCI.DAG))
34413438
return AnyTrueCombine;
34423439
return performLowerPartialReduction(N, DCI.DAG);
34433440
}

0 commit comments

Comments
 (0)