[llvm] [AMDGPU] Remove unnecessary add instructions in ctlz.i8 (PR #77615)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 00:58:11 PST 2024
================
@@ -3062,6 +3070,26 @@ static bool isCttzOpc(unsigned Opc) {
return Opc == ISD::CTTZ || Opc == ISD::CTTZ_ZERO_UNDEF;
}
+SDValue AMDGPUTargetLowering::lowerCTLZResults(SDValue Op,
+ SelectionDAG &DAG) const {
+ auto SL = SDLoc(Op);
+ auto Arg = Op.getOperand(0u);
+ auto ResultVT = Op.getValueType();
+
+ if (ResultVT != MVT::i8 && ResultVT != MVT::i16)
+ return {};
+
+ assert(isCtlzOpc(Op.getOpcode()));
+ assert(ResultVT == Arg.getValueType());
+
+ auto const LeadingZeroes = 32u - ResultVT.getFixedSizeInBits();
+ auto NewOp = DAG.getNode(ISD::ZERO_EXTEND, SL, MVT::i32, Arg);
+ auto ShiftVal = DAG.getConstant(LeadingZeroes, SL, MVT::i32);
+ NewOp = DAG.getNode(ISD::SHL, SL, MVT::i32, NewOp, ShiftVal);
+ NewOp = DAG.getNode(Op.getOpcode(), SL, MVT::i32, NewOp);
+ return DAG.getNode(ISD::TRUNCATE, SL, ResultVT, NewOp);
----------------
arsenm wrote:
Unfortunate duplication of generic legalization logic
https://github.com/llvm/llvm-project/pull/77615
More information about the llvm-commits
mailing list