This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] Add computeKnownBits support for ISD::SPLAT_VECTOR_PARTS
ClosedPublic

Authored by luke on Aug 25 2023, 8:23 AM.

Details

Summary

We can work out the known bits for a given lane by concatenating the known bits of each scalar operand.

In the description of ISD::SPLAT_VECTOR_PARTS in ISDOpcodes.h it says that the
total size of the scalar operands must cover the output element size, but I've
added a stricter assertion here that the total width of the scalar operands
must be exactly equal to the element size. It doesn't seem to trigger, and I'm
not sure if there any targets that use SPLAT_VECTOR_PARTS for anything other
than v4i32 -> v2i64 splats.

We also need to include it in isTargetCanonicalConstantNode, otherwise
returning the known bits introduces an infinite combine loop.

Diff Detail

Event Timeline

luke created this revision.Aug 25 2023, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2023, 8:23 AM
luke requested review of this revision.Aug 25 2023, 8:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2023, 8:23 AM
craig.topper accepted this revision.Aug 25 2023, 10:39 AM

LGTM

llvm/test/CodeGen/RISCV/rvv/vror-sdnode.ll
2063

There's a missed constant fold of sub of two constant splat_vector parts here. computeKnownBits is hiding it because we constant fold it inside computeKnownBits, but we should handle it in FoldConstantArithmetic

This revision is now accepted and ready to land.Aug 25 2023, 10:39 AM
luke added inline comments.Aug 28 2023, 3:23 AM
llvm/test/CodeGen/RISCV/rvv/vror-sdnode.ll
2063

Yeah, this was the first thing I tried. I found that there's a lot of logic that needs shared, and there's some other binop cases that aren't fully handled e.g. a bitcast of a splat_vector, or where one operand is bitcasted and the other isn't. Will give it a revisit.

Some other places I saw where I think we might need to handle splat_vector_parts:

SelectionDAG::isSplatValue
isConstantSplatVector/isConstantSplatVectorAllOnes/isConstantSplatVectorAllZeros/isConstOrConstSplat in SelectionDAGNodes.h
SelectionDAG::getValidShiftAmountConstant and friends
isConstantOrConstantVector in DAGCombiner