Skip to content

Commit 8f1cd06

Browse files
committed
Simplify "Optimize away mask of 63 for shl ( zext (and i32 63)))"
This reverts commit 40e9092 and replace it with a simple constant 63 mask
1 parent 40e9092 commit 8f1cd06

File tree

3 files changed

+4
-42
lines changed

3 files changed

+4
-42
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ class WebAssemblyDAGToDAGISel final : public SelectionDAGISel {
7070
bool SelectAddrOperands32(SDValue Op, SDValue &Offset, SDValue &Addr);
7171
bool SelectAddrOperands64(SDValue Op, SDValue &Offset, SDValue &Addr);
7272

73-
bool selectShiftMask(SDValue N, unsigned ShiftWidth, SDValue &ShAmt);
74-
75-
bool selectShiftMask64FromI32(SDValue N, SDValue &ShAmt) {
76-
return selectShiftMask(N, 64, ShAmt);
77-
}
7873
// Include the pieces autogenerated from the target description.
7974
#include "WebAssemblyGenDAGISel.inc"
8075

@@ -544,36 +539,6 @@ bool WebAssemblyDAGToDAGISel::SelectAddrOperands64(SDValue Op, SDValue &Offset,
544539
return SelectAddrOperands(MVT::i64, WebAssembly::CONST_I64, Op, Offset, Addr);
545540
}
546541

547-
bool WebAssemblyDAGToDAGISel::selectShiftMask(SDValue N, unsigned ShiftWidth,
548-
SDValue &ShAmt) {
549-
550-
ShAmt = N;
551-
552-
if (ShAmt.getOpcode() == ISD::AND &&
553-
isa<ConstantSDNode>(ShAmt.getOperand(1))) {
554-
const APInt &AndMask = ShAmt.getConstantOperandAPInt(1);
555-
556-
// Since the max shift amount is a power of 2 we can subtract 1 to make a
557-
// mask that covers the bits needed to represent all shift amounts.
558-
assert(isPowerOf2_32(ShiftWidth) && "Unexpected max shift amount!");
559-
APInt ShMask(AndMask.getBitWidth(), ShiftWidth - 1);
560-
561-
if (ShMask.isSubsetOf(AndMask)) {
562-
ShAmt = ShAmt.getOperand(0);
563-
} else {
564-
// SimplifyDemandedBits may have optimized the mask so try restoring any
565-
// bits that are known zero.
566-
KnownBits Known = CurDAG->computeKnownBits(ShAmt.getOperand(0));
567-
if (ShMask.isSubsetOf(AndMask | Known.Zero))
568-
ShAmt = ShAmt.getOperand(0);
569-
}
570-
return true;
571-
}
572-
573-
// TODO: Port rest of riscv if applicable
574-
return false;
575-
}
576-
577542
/// This pass converts a legalized DAG into a WebAssembly-specific DAG, ready
578543
/// for instruction scheduling.
579544
FunctionPass *llvm::createWebAssemblyISelDag(WebAssemblyTargetMachine &TM,

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,6 +3343,7 @@ static SDValue performAnyAllCombine(SDNode *N, SelectionDAG &DAG) {
33433343
Ret = DAG.getNOT(DL, Ret, MVT::i1);
33443344
return DAG.getZExtOrTrunc(Ret, DL, N->getValueType(0));
33453345
};
3346+
33463347
if (SDValue AnyTrueEQ = CombineSetCC(Intrinsic::wasm_anytrue, ISD::SETEQ,
33473348
Intrinsic::wasm_alltrue))
33483349
return AnyTrueEQ;

llvm/lib/Target/WebAssembly/WebAssemblyInstrInteger.td

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ multiclass ComparisonInt<CondCode cond, string name, bits<32> i32Inst, bits<32>
4444
!strconcat("i64.", name), i64Inst>;
4545
}
4646

47-
// ComplexPattern
48-
def shiftMask64FromI32
49-
: ComplexPattern<i32, 1, "selectShiftMask64FromI32", [], [], 0>;
50-
5147
// The spaces after the names are for aesthetic purposes only, to make
5248
// operands line up vertically after tab expansion.
5349
let isCommutable = 1 in
@@ -105,15 +101,15 @@ def : Pat<(shl I64:$lhs, (and I64:$rhs, 63)), (SHL_I64 I64:$lhs, I64:$rhs)>;
105101
def : Pat<(sra I64:$lhs, (and I64:$rhs, 63)), (SHR_S_I64 I64:$lhs, I64:$rhs)>;
106102
def : Pat<(srl I64:$lhs, (and I64:$rhs, 63)), (SHR_U_I64 I64:$lhs, I64:$rhs)>;
107103

108-
def : Pat<(shl I64:$lhs, (zext(shiftMask64FromI32 I32:$rhs))),
109-
(SHL_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
110-
111104
// Optimize away an explicit mask on a rotate count.
112105
def : Pat<(rotl I32:$lhs, (and I32:$rhs, 31)), (ROTL_I32 I32:$lhs, I32:$rhs)>;
113106
def : Pat<(rotr I32:$lhs, (and I32:$rhs, 31)), (ROTR_I32 I32:$lhs, I32:$rhs)>;
114107
def : Pat<(rotl I64:$lhs, (and I64:$rhs, 63)), (ROTL_I64 I64:$lhs, I64:$rhs)>;
115108
def : Pat<(rotr I64:$lhs, (and I64:$rhs, 63)), (ROTR_I64 I64:$lhs, I64:$rhs)>;
116109

110+
def : Pat<(shl I64:$lhs, (zext (and I32:$rhs, 63))),
111+
(SHL_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
112+
117113
defm SELECT_I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs, I32:$cond),
118114
(outs), (ins),
119115
[(set I32:$dst, (select I32:$cond, I32:$lhs, I32:$rhs))],

0 commit comments

Comments
 (0)