[llvm] [VectorCombine] Avoid inserting freeze when scalarizing extend-extract if all extracts would lead to UB on poison. (PR #164683)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 24 03:02:51 PDT 2025
================
@@ -2017,8 +2017,24 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
Value *ScalarV = Ext->getOperand(0);
if (!isGuaranteedNotToBePoison(ScalarV, &AC, dyn_cast<Instruction>(ScalarV),
- &DT))
- ScalarV = Builder.CreateFreeze(ScalarV);
+ &DT)) {
+ // Check if all lanes are extracted and all extracts trigger UB on poison.
+ // If so, we do not need to insert a freeze.
+ SmallDenseSet<uint64_t, 8> ExtractedLanes;
+ bool AllExtractsHaveUB = true;
+ for (User *U : Ext->users()) {
+ auto *Extract = cast<ExtractElementInst>(U);
+ uint64_t Idx =
+ cast<ConstantInt>(Extract->getIndexOperand())->getZExtValue();
+ ExtractedLanes.insert(Idx);
+ if (!programUndefinedIfPoison(Extract)) {
----------------
fhahn wrote:
At least initially, it should probably be enough to restrict this to cases where the extracts are in the same block as the extend, and they are guaranteed to execute, if the extend executes
https://github.com/llvm/llvm-project/pull/164683
More information about the llvm-commits
mailing list