Skip to content

Commit 48595b3

Browse files
committed
Fix 50142
Fix a miss of further vectorization introduced in 50142, where we can only achieve zext (xor (any_true), -1). Now in test case issue50142, it's converted to all_true.
1 parent b5c6245 commit 48595b3

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 32 additions & 0 deletions
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"
@@ -3248,6 +3249,37 @@ static SDValue performSETCCCombine(SDNode *N,
32483249
ISD::CondCode Cond = cast<CondCodeSDNode>(N->getOperand(2))->get();
32493250
SDLoc DL(N);
32503251
EVT VT = N->getValueType(0);
3252+
// N LHS LhsL LhsLL LhsLR InnerCond RHS Cond
3253+
// setcc (iN (bitcast (setcc vNi1 (vNiY X), <vNiY 0>, eq)), 0, eq
3254+
// => all_true (vNi1 X)
3255+
if (DCI.isBeforeLegalize() && VT.isScalarInteger() && (Cond == ISD::SETEQ) &&
3256+
(isNullConstant(RHS)) && LHS->getOpcode() == ISD::BITCAST) {
3257+
SDValue LhsL = LHS.getOperand(0);
3258+
EVT LhsLType = LhsL.getValueType();
3259+
if (LhsL.getOpcode() == ISD::SETCC) {
3260+
ISD::CondCode InnerCond =
3261+
cast<CondCodeSDNode>(LhsL->getOperand(2))->get();
3262+
if (InnerCond == ISD::SETEQ) {
3263+
SDValue LhsLL = LhsL.getOperand(0); // vNiY X
3264+
SDValue LhsLR = LhsL.getOperand(1); // <0>
3265+
unsigned NumElts = LhsLType.getVectorNumElements();
3266+
bool Vectorizable =
3267+
NumElts == 2 || NumElts == 4 || NumElts == 8 || NumElts == 16;
3268+
EVT Width = MVT::getIntegerVT(128 / NumElts);
3269+
3270+
if (Vectorizable && LhsLR.getOpcode() == ISD::BUILD_VECTOR &&
3271+
LhsLType.isFixedLengthVector()) {
3272+
return DAG.getZExtOrTrunc(
3273+
DAG.getNode(
3274+
ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
3275+
{DAG.getConstant(Intrinsic::wasm_alltrue, DL, MVT::i32),
3276+
DAG.getSExtOrTrunc(
3277+
LhsLL, DL, LhsLType.changeVectorElementType(Width))}),
3278+
DL, MVT::i1);
3279+
}
3280+
}
3281+
}
3282+
}
32513283

32523284
// setcc (iN (bitcast (vNi1 X))), 0, ne
32533285
// ==> any_true (vNi1 X)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+simd128 | FileCheck %s
2+
3+
target triple = "wasm64"
4+
5+
;CHECK:all_true:
6+
;CHECK-NEXT: .functype all_true (i64) -> (i32)
7+
;CHECK-NEXT: v128.load $push0=, 0($0):p2align=0
8+
;CHECK-NEXT: i8x16.all_true $push1=, $pop0
9+
;CHECK-NEXT: return $pop1
10+
;CHECK-NEXT: end_function
11+
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read)
12+
define hidden range(i32 0, 2) i32 @all_true(ptr noundef readonly captures(none) %a) local_unnamed_addr #0 {
13+
entry:
14+
%0 = load <16 x i8>, ptr %a, align 1
15+
%.fr = freeze <16 x i8> %0
16+
%1 = icmp eq <16 x i8> %.fr, zeroinitializer
17+
%2 = bitcast <16 x i1> %1 to i16
18+
%3 = icmp eq i16 %2, 0
19+
%conv3 = zext i1 %3 to i32
20+
ret i32 %conv3
21+
}
22+

0 commit comments

Comments
 (0)