Within the AggressiveInstCombine Pass we have an analysis/optimization that matches that pattern of the Table Based CTZ - CTTZ algorithm. Some Targets do not support/define ctz(0), but since the AggressiveInstCombine is just an extension of InstCombine, it should be a target-independent canonicalization Pass, and therefore, we decided to introduce several instructions, such as select and compare that produce canonical IR, even if the input is 0. The task for the Targets that do support that input is to handle such a case and produce an optimal assembly.
This patch optimizes the CTTZ/CTLZ instructions if the input is 0 by performing the`DAG combine`, by generating the cttz(x) & 0x1f pattern (the same goes for ctlz as well).
This is unnecessary. If it is a ISD::SELECT it has exactly 3 operands.