Skip to content

Instantly share code, notes, and snippets.

@vtjnash
Created February 22, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vtjnash/b8c6515f05187ae81940a889954b65d5 to your computer and use it in GitHub Desktop.
Save vtjnash/b8c6515f05187ae81940a889954b65d5 to your computer and use it in GitHub Desktop.
some likely looking GVN bugs
diff -rpu llvm-6.0.0.src/lib/Transforms/Scalar/GVN.cpp llvm-6.0.0-VNpatch2/lib/Transforms/Scalar/GVN.cpp
--- llvm-6.0.0.src/lib/Transforms/Scalar/GVN.cpp 2017-12-08 19:21:41.000000000 -0500
+++ llvm-6.0.0-VNpatch2/lib/Transforms/Scalar/GVN.cpp 2018-07-19 16:35:26.000000000 -0400
@@ -871,6 +871,10 @@ bool GVN::AnalyzeLoadAvailability(LoadIn
// read by the load, we can extract the bits we need for the load from the
// stored value.
if (StoreInst *DepSI = dyn_cast<StoreInst>(DepInfo.getInst())) {
+ if (DepSI->getValueOperand()->getType() != LI->getType() &&
+ !canCoerceMustAliasedValueToLoad(DepSI->getValueOperand(),
+ LI->getType(), DL))
+ return false;
// Can't forward from non-atomic to atomic without violating memory model.
if (Address && LI->isAtomic() <= DepSI->isAtomic()) {
int Offset =
@@ -887,6 +891,9 @@ bool GVN::AnalyzeLoadAvailability(LoadIn
// load i8* (P+1)
// if we have this, replace the later with an extraction from the former.
if (LoadInst *DepLI = dyn_cast<LoadInst>(DepInfo.getInst())) {
+ if (LD->getType() != DepLI->getType() &&
+ !canCoerceMustAliasedValueToLoad(LD, DepLI->getType(), DL))
+ return false;
// If this is a clobber and L is the first instruction in its block, then
// we have the first instruction in the entry block.
// Can't forward from non-atomic to atomic without violating memory model.
@@ -904,6 +911,8 @@ bool GVN::AnalyzeLoadAvailability(LoadIn
// If the clobbering value is a memset/memcpy/memmove, see if we can
// forward a value on from it.
if (MemIntrinsic *DepMI = dyn_cast<MemIntrinsic>(DepInfo.getInst())) {
+ if (DL.isNonIntegralPointerType(LD->getType())) // check canCoerceMustAliasedValueToLoad(LD, LI->getType(), DL))
+ return false;
if (Address && !LI->isAtomic()) {
int Offset = analyzeLoadFromClobberingMemInst(LI->getType(), Address,
DepMI, DL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment