[PATCH] D12957: Fix "Got assumption for the wrong function!" assert

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 03:49:09 PDT 2015


apilipenko created this revision.
apilipenko added a reviewer: chandlerc.
apilipenko added a subscriber: llvm-commits.

define void @main(i8* %a) {
  call i8 @foo(i8* %a)
  ret void
}

declare void @llvm.assume(i1 %cond)
define i8 @foo(i8* align 8 %a) {
  call void @llvm.assume(i1 1)
  %res = load i8, i8* %a
  ret i8 %res
}

opt -S -inline for the piece of code above fails with an assertion: 
opt: /home/apilipenko/llvm-upstream/llvm/lib/Analysis/ValueTracking.cpp:719: void computeKnownBitsFromAssume(llvm::Value*, llvm::APInt&, llvm::APInt&, const llvm::DataLayout&, unsigned int, const {anonymous}::Query&): Assertion `I->getParent()->getParent() == Q.CxtI->getParent()->getParent() && "Got assumption for the wrong function!"' failed.

That happens because InlineFunction AddAlignmentAssumptions passes incorrect assumption cache to getKnownAlignment. It asks about caller's value alignment, but passes callee AC. Caller's AC must be passed instead.

This bug was introduced by "[PM] Split the AssumptionTracker immutable pass into two separate APIs" patch (http://reviews.llvm.org/rL225131)

http://reviews.llvm.org/D12957

Files:
  lib/Transforms/Utils/InlineFunction.cpp

Index: lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- lib/Transforms/Utils/InlineFunction.cpp
+++ lib/Transforms/Utils/InlineFunction.cpp
@@ -741,7 +741,7 @@
       // caller, then don't bother inserting the assumption.
       Value *Arg = CS.getArgument(I->getArgNo());
       if (getKnownAlignment(Arg, DL, CS.getInstruction(),
-                            &IFI.ACT->getAssumptionCache(*CalledFunc),
+                            &IFI.ACT->getAssumptionCache(*CS.getCaller()),
                             &DT) >= Align)
         continue;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12957.35071.patch
Type: text/x-patch
Size: 608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150918/c15363d0/attachment.bin>


More information about the llvm-commits mailing list