@@ -761,6 +761,23 @@ Value *GenXPacketize::packetizeConstant(Constant *C) {
761
761
}
762
762
}
763
763
764
+ // Helper: vectorize scalar MD_range metadata for a vector instruction
765
+ static void vectorizeRangeMetadata (Instruction *OldCI, Instruction *NewCI) {
766
+ auto *OldRangeMD = OldCI->getMetadata (LLVMContext::MD_range);
767
+ if (!OldRangeMD)
768
+ return ;
769
+ Type *Ty = NewCI->getType ();
770
+
771
+ // Currently, llvm15/16 work inconsistently with MD_range metadata for vectors.
772
+ // Link1: Verifier.cpp Verifier::visitRangeMetadata
773
+ // -> "Range types must match instruction type!"
774
+ // Link2: ValueTracking.cpp llvm::computeKnownBitsFromRangeMetadata
775
+ // -> ConstantInt *Lower = ... Ranges.getOperand(2 * i + 0)
776
+ if (auto *VecTy = dyn_cast<VectorType>(Ty))
777
+ NewCI->setMetadata (LLVMContext::MD_range, nullptr );
778
+ return ;
779
+ }
780
+
764
781
// ////////////////////////////////////////////////////////////////////////
765
782
// / @brief Packetize an LLVM intrinsic. Generally this means replacing
766
783
// / a scalar intrinsic function call with a vectored equivalent.
@@ -1659,8 +1676,10 @@ Value *GenXPacketize::packetizeInstruction(Instruction *Inst) {
1659
1676
DII->replaceVariableLocationOp (Inst, Result);
1660
1677
}
1661
1678
// Copy any metadata to new instruction
1662
- if (Result != Inst && isa<Instruction>(Result))
1679
+ if (Result != Inst && isa<Instruction>(Result)) {
1663
1680
cast<Instruction>(Result)->copyMetadata (*Inst);
1681
+ vectorizeRangeMetadata (Inst, dyn_cast<Instruction>(Result));
1682
+ }
1664
1683
}
1665
1684
return Result;
1666
1685
}
0 commit comments