[llvm] Remove unnecessary add instructions in ctlz.i8 (PR #77615)

Leon Clark via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 07:27:15 PST 2024


================
@@ -3062,6 +3068,25 @@ static bool isCttzOpc(unsigned Opc) {
   return Opc == ISD::CTTZ || Opc == ISD::CTTZ_ZERO_UNDEF;
 }
 
+void AMDGPUTargetLowering::replaceCTLZResults(
+    SDValue Op, SelectionDAG &DAG, SmallVectorImpl<SDValue> &Results) const {
+  auto SL = SDLoc(Op);
+  auto Arg = Op.getOperand(0u);
+  auto ResultVT = Op.getValueType();
+
+  if (ResultVT != MVT::i8)
+    return;
+
+  assert(isCtlzOpc(Op.getOpcode()));
+  assert(ResultVT == Arg.getValueType());
+
+  auto SubVal = DAG.getConstant(24u, SL, MVT::i32);
+  auto NewOp = DAG.getNode(ISD::ZERO_EXTEND, SL, MVT::i32, Arg);
+  NewOp = DAG.getNode(Op.getOpcode(), SL, MVT::i32, NewOp);
+  NewOp = DAG.getNode(ISD::SUB, SL, MVT::i32, NewOp, SubVal);
+  Results.push_back(DAG.getNode(ISD::TRUNCATE, SL, ResultVT, NewOp));
----------------
PeddleSpam wrote:

I was following the convention of other backends to disambiguate the function from `LowerCTLZ_CTTZ`. Happy to do the push in `ReplaceNodeResults` though.

https://github.com/llvm/llvm-project/pull/77615


More information about the llvm-commits mailing list