Index: llvm/lib/Transforms/Scalar/LICM.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LICM.cpp +++ llvm/lib/Transforms/Scalar/LICM.cpp @@ -109,6 +109,10 @@ "licm-control-flow-hoisting", cl::Hidden, cl::init(false), cl::desc("Enable control flow (and PHI) hoisting in LICM")); +static cl::opt AllowDataRaces("allow-data-races", cl::Hidden, + cl::init(false), + cl::desc("Allow data races in LICM pass")); + static cl::opt MaxNumUsesTraversed( "licm-max-num-uses-traversed", cl::Hidden, cl::init(8), cl::desc("Max num uses visited for identifying load " @@ -1851,7 +1855,8 @@ MSSAU.createMemoryAccessAfter(NewSI, nullptr, MSSAInsertPoint); } MSSAInsertPts[i] = NewMemAcc; - MSSAU.insertDef(cast(NewMemAcc), true); + MSSAU.insertDef(cast(NewMemAcc), + AllowDataRaces ? false : true); // FIXME: true for safety, false may still be correct. } } @@ -2111,7 +2116,7 @@ // stores along paths which originally didn't have them without violating the // memory model. if (!SafeToInsertStore) { - if (IsKnownThreadLocalObject) + if (IsKnownThreadLocalObject || AllowDataRaces) SafeToInsertStore = true; else { Value *Object = getUnderlyingObject(SomePtr);