[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:16:49 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)
----------------
PeddleSpam wrote:

I didn't see the same issue with `i16`. The `i8` case happens because we first zero-extend to `i16` and then later to `i32`. Both times a subtraction is needed to account for the leading zeroes, which is where we get the two add/sub ops.

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


More information about the llvm-commits mailing list