[PATCH] D21165: Disable MSan-hostile loop unswitching.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 10 11:42:56 PDT 2016
eugenis updated this revision to Diff 60382.
Repository:
rL LLVM
http://reviews.llvm.org/D21165
Files:
lib/Transforms/Scalar/LoopUnswitch.cpp
Index: lib/Transforms/Scalar/LoopUnswitch.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnswitch.cpp
+++ lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -188,6 +188,8 @@
BasicBlock *loopHeader;
BasicBlock *loopPreheader;
+ LoopSafetyInfo SafetyInfo;
+
// LoopBlocks contains all of the basic blocks of the loop, including the
// preheader of the loop, the body of the loop, and the exit blocks of the
// loop, in that order.
@@ -431,6 +433,9 @@
currentLoop = L;
Function *F = currentLoop->getHeader()->getParent();
+ if (F->hasFnAttribute(Attribute::SanitizeMemory))
+ computeLoopSafetyInfo(&SafetyInfo, L);
+
EnabledPGO = F->getEntryCount().hasValue();
if (LoopUnswitchWithBlockFrequency && EnabledPGO) {
@@ -524,12 +529,26 @@
return false;
}
+ bool SanitizingMemory = currentLoop->getHeader()->getParent()->hasFnAttribute(
+ Attribute::SanitizeMemory);
+
// Loop over all of the basic blocks in the loop. If we find an interior
// block that is branching on a loop-invariant condition, we can unswitch this
// loop.
for (Loop::block_iterator I = currentLoop->block_begin(),
E = currentLoop->block_end(); I != E; ++I) {
TerminatorInst *TI = (*I)->getTerminator();
+
+ // Unswitching on a potentially uninitialized predicate is not
+ // MSan-friendly. Limit this to the cases when the original predicate is
+ // guaranteed to execute, to avoid creating a use-of-uninitialized-value
+ // in the code that did not have one.
+ // This is a workaround for the discrepancy between LLVM IR and MSan
+ // semantics. See PR28054 for more details.
+ if (SanitizingMemory &&
+ !isGuaranteedToExecute(*TI, DT, currentLoop, &SafetyInfo))
+ continue;
+
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
// If this isn't branching on an invariant condition, we can't unswitch
// it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21165.60382.patch
Type: text/x-patch
Size: 1966 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160610/03c6258d/attachment.bin>
More information about the llvm-commits
mailing list