Index: lib/Transforms/Scalar/GVN.cpp =================================================================== --- lib/Transforms/Scalar/GVN.cpp +++ lib/Transforms/Scalar/GVN.cpp @@ -1701,6 +1701,10 @@ /// Attempt to eliminate a load whose dependencies are /// non-local by performing PHI construction. bool GVN::processNonLocalLoad(LoadInst *LI) { + // non-local speculations are not allowed under asan. + if (LI->getParent()->getParent()->hasFnAttribute(Attribute::SanitizeAddress)) + return false; + // Step 1: Find the non-local dependencies of the load. LoadDepVect Deps; MD->getNonLocalPointerDependency(LI, Deps); @@ -1913,7 +1917,6 @@ // we have the first instruction in the entry block. if (DepLI == L) return false; - int Offset = AnalyzeLoadFromClobberingLoad( L->getType(), L->getPointerOperand(), DepLI, DL); if (Offset != -1) Index: test/Transforms/GVN/no_speculative_loads_with_asan.ll =================================================================== --- /dev/null +++ test/Transforms/GVN/no_speculative_loads_with_asan.ll @@ -0,0 +1,57 @@ +; RUN: opt -O3 -S %s | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +declare noalias i8* @_Znam(i64) #1 + +define i32 @TestNoAsan() { + %1 = tail call noalias i8* @_Znam(i64 2) + %2 = getelementptr inbounds i8, i8* %1, i64 1 + store i8 0, i8* %2, align 1 + store i8 0, i8* %1, align 1 + %3 = bitcast i8* %1 to i16* + %4 = load i16, i16* %3, align 4 + %5 = icmp eq i16 %4, 0 + br i1 %5, label %11, label %6 + +;