[llvm] [DAG] Fold trunc(srl(extract_elt(vec,c1),c2)) -> extract_elt(bitcast(vec),c3) (PR #107987)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 04:30:57 PDT 2024
================
@@ -15142,26 +15142,42 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
// Note: We only run this optimization after type legalization (which often
// creates this pattern) and before operation legalization after which
// we need to be more careful about the vector instructions that we generate.
- if (N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT &&
- LegalTypes && !LegalOperations && N0->hasOneUse() && VT != MVT::i1) {
- EVT VecTy = N0.getOperand(0).getValueType();
- EVT ExTy = N0.getValueType();
+ if (LegalTypes && !LegalOperations && VT.isScalarInteger() && VT != MVT::i1 &&
+ N0->hasOneUse()) {
EVT TrTy = N->getValueType(0);
+ SDValue Src = N0;
+
+ // Check for cases where we shift down an upper element before truncation.
+ int EltOffset = 0;
+ if (Src.getOpcode() == ISD::SRL && Src.getOperand(0)->hasOneUse()) {
+ if (auto ShAmt = DAG.getValidShiftAmount(Src)) {
+ if ((*ShAmt % TrTy.getSizeInBits()) == 0) {
----------------
RKSimon wrote:
ShAmt is optional<uint64_t> not TypeSize so I don't think that would work
https://github.com/llvm/llvm-project/pull/107987
More information about the llvm-commits
mailing list