[llvm] [DAGCombiner][RISCV] Handle truncating splats in isNeutralConstant (PR #87338)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 04:47:18 PDT 2024


================
@@ -11549,30 +11549,31 @@ bool llvm::isNeutralConstant(unsigned Opcode, SDNodeFlags Flags, SDValue V,
                              unsigned OperandNo) {
   // NOTE: The cases should match with IR's ConstantExpr::getBinOpIdentity().
   // TODO: Target-specific opcodes could be added.
-  if (auto *Const = isConstOrConstSplat(V)) {
+  if (auto *ConstV = isConstOrConstSplat(V, false, true)) {
+    APInt Const = ConstV->getAPIntValue().trunc(V.getScalarValueSizeInBits());
----------------
dtcxzyw wrote:

> This patch handles truncating splats by getting the APInt value and truncating it. We almost don't need to do this since most of the neutral elements are either one/zero/all ones, but it will make a difference for smax and smin.

Can you add some tests for smax/smin?


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


More information about the llvm-commits mailing list