[llvm] [AMDGPU] Elide bitcast fold i64 imm to build_vector (PR #154115)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 4 06:51:01 PDT 2025
================
@@ -14584,13 +14584,39 @@ SITargetLowering::performExtractVectorEltCombine(SDNode *N,
return V;
}
+ // EXTRACT_VECTOR_ELT (v2i32 bitcast (i64/f64:k), Idx)
+ // =>
+ // i32:Lo(k) if Idx == 0, or
+ // i32:Hi(k) if Idx == 1
+ auto *Idx = dyn_cast<ConstantSDNode>(N->getOperand(1));
+ if (Vec.getOpcode() == ISD::BITCAST && VecVT == MVT::v2i32 && Idx) {
+ SDLoc SL(N);
+ SDValue PeekThrough = peekThroughBitcasts(Vec);
+ auto *KImm = dyn_cast<ConstantSDNode>(PeekThrough);
+ if (KImm && KImm->getValueType(0).getSizeInBits() == 64) {
+ uint64_t KImmValue = KImm->getZExtValue();
+ if (Idx->getZExtValue() == 0)
+ return DAG.getConstant(Lo_32(KImmValue), SL, MVT::i32);
+ else
+ return DAG.getConstant(Hi_32(KImmValue), SL, MVT::i32);
----------------
arsenm wrote:
```suggestion
return DAG.getConstant(KImmValue >> (32 * Idx->getZExtValue()), SL, MVT::i32);
```
No else after return
https://github.com/llvm/llvm-project/pull/154115
More information about the llvm-commits
mailing list