From 4389252c58b783ce5b62b1942ea4b85eed556fce Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 22 Sep 2023 00:14:31 -0700 Subject: [PATCH] Revert "[DAG] getNode() - remove oneuse limit from (zext (trunc (assertzext x))) -> (assertzext x) fold" This reverts commit 05926a5a557878aa233ac8431b3acddf54422e58. Caused AArch64 crash #12 0x00007f09eec09181 skipExtensionForVectorMULL(llvm::SDNode*, llvm::SelectionDAG&) #13 0x00007f09eec08289 llvm::AArch64TargetLowering::LowerMUL(llvm::SDValue, llvm::SelectionDAG&) const #14 0x00007f09eec1a3fd llvm::AArch64TargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const #15 0x00007f09dc8586a7 (anonymous namespace)::VectorLegalizer::LowerOperationWrapper(llvm::SDNode*, llvm::SmallVectorImpl&) --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +- llvm/lib/Target/X86/X86ISelLoweringCall.cpp | 3 +-- llvm/test/CodeGen/AArch64/setcc_knownbits.ll | 2 ++ llvm/test/CodeGen/RISCV/rvv/fold-vp-fadd-and-vp-fmul.ll | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index f12db53c7f08..c15f056551b9 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5700,7 +5700,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT, if (OpOpcode == ISD::TRUNCATE) { SDValue OpOp = N1.getOperand(0); if (OpOp.getValueType() == VT) { - if (OpOp.getOpcode() == ISD::AssertZext) { + if (OpOp.getOpcode() == ISD::AssertZext && N1->hasOneUse()) { APInt HiBits = APInt::getBitsSetFrom(VT.getScalarSizeInBits(), N1.getScalarValueSizeInBits()); if (MaskedValueIsZero(OpOp, HiBits)) { diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp index c47ddae072b4..754d2042105e 100644 --- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp +++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp @@ -2645,8 +2645,7 @@ bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, for (;;) { // Look through nodes that don't alter the bits of the incoming value. unsigned Op = Arg.getOpcode(); - if (Op == ISD::ZERO_EXTEND || Op == ISD::ANY_EXTEND || Op == ISD::BITCAST || - Op == ISD::AssertZext) { + if (Op == ISD::ZERO_EXTEND || Op == ISD::ANY_EXTEND || Op == ISD::BITCAST) { Arg = Arg.getOperand(0); continue; } diff --git a/llvm/test/CodeGen/AArch64/setcc_knownbits.ll b/llvm/test/CodeGen/AArch64/setcc_knownbits.ll index af5c1586a4c6..aa62a7aa176c 100644 --- a/llvm/test/CodeGen/AArch64/setcc_knownbits.ll +++ b/llvm/test/CodeGen/AArch64/setcc_knownbits.ll @@ -4,6 +4,8 @@ define i1 @load_bv_v4i8(i1 zeroext %a) { ; CHECK-LABEL: load_bv_v4i8: ; CHECK: // %bb.0: +; CHECK-NEXT: cmp w0, #0 +; CHECK-NEXT: cset w0, ne ; CHECK-NEXT: ret %b = zext i1 %a to i32 %c = icmp eq i32 %b, 1 diff --git a/llvm/test/CodeGen/RISCV/rvv/fold-vp-fadd-and-vp-fmul.ll b/llvm/test/CodeGen/RISCV/rvv/fold-vp-fadd-and-vp-fmul.ll index f773de3b518c..1eccaaa26154 100644 --- a/llvm/test/CodeGen/RISCV/rvv/fold-vp-fadd-and-vp-fmul.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fold-vp-fadd-and-vp-fmul.ll @@ -62,9 +62,9 @@ define @fma_reassociate( %a, @llvm.vp.fmul.nxv1f64( %a, %b, %m, i32 %vl) %2 = call fast @llvm.vp.fmul.nxv1f64( %c, %d, %m, i32 %vl)