[llvm] [SimplifyCFG] Drop UB-implying attributes when hoisting speculatively (PR #226746)
Mian Miftah via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 27 09:49:17 PDT 2026
================
@@ -2053,6 +2053,20 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(Instruction *TI,
I1->applyMergedLocation(I1->getDebugLoc(), I2->getDebugLoc());
I2->eraseFromParent();
}
+ // I1 now executes before the instructions we skipped.
+ unsigned SkippedFlags = 0;
+ for (const SuccIterPair &P : SuccIterPairs)
+ SkippedFlags |= P.second;
+ if (SkippedFlags & SkipImplicitControlFlow) {
+ // One of them may throw or not return, so I1 is speculated.
+ I1->dropUBImplyingAttrsAndMetadata();
+ } else if (SkippedFlags & SkipSideEffect) {
+ // One of them may write memory, for example allocate or free it, so
+ // metadata that only holds at I1's old position may not hold here.
+ I1->setMetadata(LLVMContext::MD_dereferenceable, nullptr);
+ I1->setMetadata(LLVMContext::MD_dereferenceable_or_null, nullptr);
----------------
mmiftahx wrote:
Okay makes sense, the cast shouldn't move above the exposure in the first place.
I removed that part and its tests, so this only handles the speculative case now.
https://github.com/llvm/llvm-project/pull/226746
More information about the llvm-commits
mailing list