From 0fc5f4b52460c091608837f05a726c7383898229 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Thu, 18 Jan 2024 07:34:08 -0800 Subject: [PATCH] [DAG] Set nneg flag when forming zext in demanded bits (#72281) We do the same for the analogous transform in DAGCombine, but this case was missed in the recent patch which added support for zext nneg. Sorry for the lack of test coverage. Not sure how to exercise this piece of logic. It appears to have only minimal impact on LIT tests (only test/CodeGen/X86/wide-scalar-shift-by-byte-multiple-legalization.ll), and even then, the changes without it appear uninteresting. Maybe we should remove this transform instead? --- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 3bbef6e6d85d..b8ed02e268b1 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -2483,8 +2483,12 @@ bool TargetLowering::SimplifyDemandedBits( if (Known.isNonNegative()) { unsigned Opc = IsVecInReg ? ISD::ZERO_EXTEND_VECTOR_INREG : ISD::ZERO_EXTEND; - if (!TLO.LegalOperations() || isOperationLegal(Opc, VT)) - return TLO.CombineTo(Op, TLO.DAG.getNode(Opc, dl, VT, Src)); + if (!TLO.LegalOperations() || isOperationLegal(Opc, VT)) { + SDNodeFlags Flags; + if (!IsVecInReg) + Flags.setNonNeg(true); + return TLO.CombineTo(Op, TLO.DAG.getNode(Opc, dl, VT, Src, Flags)); + } } // Attempt to avoid multi-use ops if we don't need anything from them.