Skip to content

Commit 4ced462

Browse files
committed
check true/false value being alloca
1 parent e987628 commit 4ced462

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

llvm/lib/Target/AMDGPU/AMDGPUVectorIdiom.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ AMDGPUVectorIdiomCombinePass::run(Function &F, FunctionAnalysisManager &FAM) {
486486
Value *Fv = SI->getFalseValue();
487487
dumpPtrForms("true", T);
488488
dumpPtrForms("false", Fv);
489+
dbgs() << " trueIsAlloca=" << (hasAllocaUnderlyingObject(T) ? "true" : "false") << '\n';
490+
dbgs() << " falseIsAlloca=" << (hasAllocaUnderlyingObject(Fv) ? "true" : "false") << '\n';
489491
}
490492
};
491493

@@ -538,21 +540,30 @@ AMDGPUVectorIdiomCombinePass::run(Function &F, FunctionAnalysisManager &FAM) {
538540
continue;
539541
}
540542

541-
// Focus on alloca-based memcpy operations to reduce scratch usage
542-
bool DstIsAlloca = hasAllocaUnderlyingObject(Dst);
543-
bool SrcIsAlloca = hasAllocaUnderlyingObject(Src);
544-
if (!DstIsAlloca && !SrcIsAlloca) {
545-
LLVM_DEBUG(dbgs() << "[AMDGPUVectorIdiom] Skip: neither source nor "
546-
<< "destination underlying object is alloca\n");
547-
continue;
548-
}
549-
543+
// Check if we have select instructions and if their operands are alloca-based
544+
bool ShouldTransform = false;
550545
if (auto *Sel = dyn_cast<SelectInst>(Src)) {
551-
Changed |= Impl.transformSelectMemcpySource(*MT, *Sel, DL, &DT, &AC);
546+
bool TrueIsAlloca = hasAllocaUnderlyingObject(Sel->getTrueValue());
547+
bool FalseIsAlloca = hasAllocaUnderlyingObject(Sel->getFalseValue());
548+
if (TrueIsAlloca || FalseIsAlloca) {
549+
ShouldTransform = true;
550+
Changed |= Impl.transformSelectMemcpySource(*MT, *Sel, DL, &DT, &AC);
551+
} else {
552+
LLVM_DEBUG(dbgs() << "[AMDGPUVectorIdiom] Skip: select source operands "
553+
<< "are not alloca-based\n");
554+
}
552555
continue;
553556
}
554557
if (auto *Sel = dyn_cast<SelectInst>(Dst)) {
555-
Changed |= Impl.transformSelectMemcpyDest(*MT, *Sel);
558+
bool TrueIsAlloca = hasAllocaUnderlyingObject(Sel->getTrueValue());
559+
bool FalseIsAlloca = hasAllocaUnderlyingObject(Sel->getFalseValue());
560+
if (TrueIsAlloca || FalseIsAlloca) {
561+
ShouldTransform = true;
562+
Changed |= Impl.transformSelectMemcpyDest(*MT, *Sel);
563+
} else {
564+
LLVM_DEBUG(dbgs() << "[AMDGPUVectorIdiom] Skip: select destination operands "
565+
<< "are not alloca-based\n");
566+
}
556567
continue;
557568
}
558569

0 commit comments

Comments
 (0)