[RISCV] Fix crash in combinePExtTruncate for truncate(srl) without MUL/SUB (#186141)

combinePExtTruncate is called from performTRUNCATECombine when the
P-extension is enabled. It attempts to match patterns like
truncate(srl(mul/sub(...), shamt)) and combine them into P-extension
narrowing shift instructions (e.g. PNSRLI, PNSRAI).

However, after extracting the shift input operand `Op` from the SRL
node, the function unconditionally accessed Op.getOperand(0) and
Op.getOperand(1) without first verifying that Op has at least two
operands. For example, when combining:

```
  truncate(v2i16
    srl(v2i32
      bitcast(v2i32 i64),   <-- Op = bitcast, a unary op with 1 operand
      BUILD_VECTOR <8, 8>))
```

Op is a BITCAST node (unary, only 1 operand), so accessing
Op.getOperand(1) triggers an out-of-bounds assertion:

```
  Assertion `Num < NumOperands && "Invalid child # of SDNode!"' failed.
```

Add an early return when Op has fewer than two operands.

GitOrigin-RevId: bcdf3c930b8bbf59e7fc65da37c5baa89aa73f30
2 files changed