From: Nikita Popov Date: Sat, 27 Mar 2021 11:58:46 +0000 (+0100) Subject: [BasicAA] Clarify entry values of GetLinearExpression() (NFC) X-Git-Tag: llvmorg-14-init~11116 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=60f3e8fbe44f12ea28760c2771f8bf48dc08abe8;p=platform%2Fupstream%2Fllvm.git [BasicAA] Clarify entry values of GetLinearExpression() (NFC) A number of variables need to be correctly initialized on entry to GetLinearExpression() for the implementation to behave reasonably. The fact that SExtBits can currenlty be non-zero on entry is a bug, as demonstrated by the added test: For implicit sexts by the GEP, we do currently skip legality checks. --- diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index ab0d180a99e1..6a6ddd65d5d5 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -237,6 +237,9 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL, unsigned &SExtBits, const DataLayout &DL, unsigned Depth, AssumptionCache *AC, DominatorTree *DT, bool &NSW, bool &NUW) { assert(V->getType()->isIntegerTy() && "Not an integer value"); + // TODO: SExtBits can be non-zero on entry. + assert(Scale == 0 && Offset == 0 && ZExtBits == 0 && NSW == true && + NUW == true && "Incorrect default values"); // Limit our recursion depth. if (Depth == 6) { @@ -251,7 +254,7 @@ static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL, // than the constant's (the Offset's always as wide as the outermost call), // so we'll zext here and process any extension in the isa & // isa cases below. - Offset += Const->getValue().zextOrSelf(Offset.getBitWidth()); + Offset = Const->getValue().zextOrSelf(Offset.getBitWidth()); assert(Scale == 0 && "Constant values don't have a scale"); return V; } diff --git a/llvm/test/Analysis/BasicAA/zext.ll b/llvm/test/Analysis/BasicAA/zext.ll index 2e25734be775..050e9d3b0724 100644 --- a/llvm/test/Analysis/BasicAA/zext.ll +++ b/llvm/test/Analysis/BasicAA/zext.ll @@ -264,5 +264,17 @@ define void @test_shl_nsw_sext(i8* %p, i32 %x) { ret void } +; CHECK-LABEL: Function: test_implicit_sext +; CHECK: MustAlias: i8* %p.1, i8* %p.2 +; TODO: Should be MayAlias. +define void @test_implicit_sext(i8* %p, i32 %x) { + %add = add i32 %x, 1 + %ext = sext i32 %x to i64 + %ext.add = add i64 %ext, 1 + %p.1 = getelementptr i8, i8* %p, i32 %add + %p.2 = getelementptr i8, i8* %p, i64 %ext.add + ret void +} + ; Function Attrs: nounwind declare noalias i8* @malloc(i64)