<div dir="ltr">This was already fixed in a subsequent commit.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 20, 2014 at 2:26 AM, Renato Golin <span dir="ltr"><<a href="mailto:renato.golin@linaro.org" target="_blank">renato.golin@linaro.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Chandler,<br>
<br>
Seems this commit broke our ARM64 LNT:<br>
<br>
<a href="http://lab.llvm.org:8011/builders/clang-aarch64-lnt/builds/1561" target="_blank">http://lab.llvm.org:8011/builders/clang-aarch64-lnt/builds/1561</a><br>
<br>
The error on both cases:<br>
<br>
clang: /home/bgabor/work/lntbot/slave/clang-aarch64-lnt/llvm.src/include/llvm/Support/Casting.h:95:<br>
static bool llvm::isa_impl_cl<To, const From*>::doit(const From*)<br>
[with To = llvm::BranchInst; From = llvm::TerminatorInst]: Assertion<br>
`Val && "isa<> used on a null pointer"' failed.<br>
0 clang 0x000000000254f190 llvm::sys::PrintStackTrace(_IO_FILE*) + 52<br>
Stack dump:<br>
1. <eof> parser at end of file<br>
2. Per-module optimization passes<br>
3. Running pass 'CallGraph Pass Manager' on module<br>
'/home/bgabor/work/lntbot/slave/clang-aarch64-lnt/test-suite/MultiSource/Benchmarks/MiBench/consumer-typeset/z29.c'.<br>
4. Running pass 'Jump Threading' on function '@ChildSymWithCode'<br>
qemu: uncaught target signal 6 (Aborted) - core dumped<br>
clang: error: unable to execute command: Aborted (core dumped)<br>
clang: error: clang frontend command failed due to signal (use -v to<br>
see invocation)<br>
clang version 3.6.0 (trunk 220178)<br>
Target: aarch64-unknown-linux-gnu<br>
<br>
cheers,<br>
--renato<br>
<div class="HOEnZb"><div class="h5"><br>
On 20 October 2014 01:24, Chandler Carruth <<a href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>> wrote:<br>
> Author: chandlerc<br>
> Date: Sun Oct 19 19:24:14 2014<br>
> New Revision: 220178<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=220178&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=220178&view=rev</a><br>
> Log:<br>
> Teach the load analysis driving core instcombine logic and other bits of<br>
> logic to look through pointer casts, making them trivially stronger in<br>
> the face of loads and stores with intervening pointer casts.<br>
><br>
> I've included a few test cases that demonstrate the kind of folding<br>
> instcombine can do without pointer casts and then variations which<br>
> obfuscate the logic through bitcasts. Without this patch, the variations<br>
> all fail to optimize fully.<br>
><br>
> This is more important now than it has been in the past as I've started<br>
> moving the load canonicialization to more closely follow the value type<br>
> requirements rather than the pointer type requirements and thus this<br>
> needs to be prepared for more pointer casts. When I made the same change<br>
> to stores several test cases regressed without logic along these lines<br>
> so I wanted to systematically improve matters first.<br>
><br>
> Modified:<br>
> llvm/trunk/lib/Analysis/Loads.cpp<br>
> llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp<br>
> llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br>
> llvm/trunk/test/Transforms/InstCombine/select.ll<br>
><br>
> Modified: llvm/trunk/lib/Analysis/Loads.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=220178&r1=220177&r2=220178&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=220178&r1=220177&r2=220178&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/Loads.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/Loads.cpp Sun Oct 19 19:24:14 2014<br>
> @@ -86,6 +86,9 @@ bool llvm::isSafeToLoadUnconditionally(V<br>
> }<br>
> }<br>
><br>
> + PointerType *AddrTy = cast<PointerType>(V->getType());<br>
> + uint64_t LoadSize = DL ? DL->getTypeStoreSize(AddrTy->getElementType()) : 0;<br>
> +<br>
> // If we found a base allocated type from either an alloca or global variable,<br>
> // try to see if we are definitively within the allocated region. We need to<br>
> // know the size of the base type and the loaded type to do anything in this<br>
> @@ -96,8 +99,6 @@ bool llvm::isSafeToLoadUnconditionally(V<br>
><br>
> if (Align <= BaseAlign) {<br>
> // Check if the load is within the bounds of the underlying object.<br>
> - PointerType *AddrTy = cast<PointerType>(V->getType());<br>
> - uint64_t LoadSize = DL->getTypeStoreSize(AddrTy->getElementType());<br>
> if (ByteOffset + LoadSize <= DL->getTypeAllocSize(BaseType) &&<br>
> (Align == 0 || (ByteOffset % Align) == 0))<br>
> return true;<br>
> @@ -111,6 +112,10 @@ bool llvm::isSafeToLoadUnconditionally(V<br>
> // the load entirely).<br>
> BasicBlock::iterator BBI = ScanFrom, E = ScanFrom->getParent()->begin();<br>
><br>
> + // We can at least always strip pointer casts even though we can't use the<br>
> + // base here.<br>
> + V = V->stripPointerCasts();<br>
> +<br>
> while (BBI != E) {<br>
> --BBI;<br>
><br>
> @@ -120,13 +125,25 @@ bool llvm::isSafeToLoadUnconditionally(V<br>
> !isa<DbgInfoIntrinsic>(BBI))<br>
> return false;<br>
><br>
> - if (LoadInst *LI = dyn_cast<LoadInst>(BBI)) {<br>
> - if (AreEquivalentAddressValues(LI->getOperand(0), V))<br>
> - return true;<br>
> - } else if (StoreInst *SI = dyn_cast<StoreInst>(BBI)) {<br>
> - if (AreEquivalentAddressValues(SI->getOperand(1), V))<br>
> - return true;<br>
> - }<br>
> + Value *AccessedPtr;<br>
> + if (LoadInst *LI = dyn_cast<LoadInst>(BBI))<br>
> + AccessedPtr = LI->getPointerOperand();<br>
> + else if (StoreInst *SI = dyn_cast<StoreInst>(BBI))<br>
> + AccessedPtr = SI->getPointerOperand();<br>
> + else<br>
> + continue;<br>
> +<br>
> + // Handle trivial cases even w/o DataLayout or other work.<br>
> + if (AccessedPtr == V)<br>
> + return true;<br>
> +<br>
> + if (!DL)<br>
> + continue;<br>
> +<br>
> + auto *AccessedTy = cast<PointerType>(AccessedPtr->getType());<br>
> + if (AreEquivalentAddressValues(AccessedPtr->stripPointerCasts(), V) &&<br>
> + LoadSize <= DL->getTypeStoreSize(AccessedTy->getElementType()))<br>
> + return true;<br>
> }<br>
> return false;<br>
> }<br>
> @@ -157,12 +174,12 @@ Value *llvm::FindAvailableLoadedValue(Va<br>
> if (MaxInstsToScan == 0)<br>
> MaxInstsToScan = ~0U;<br>
><br>
> + Type *AccessTy = cast<PointerType>(Ptr->getType())->getElementType();<br>
> +<br>
> // If we're using alias analysis to disambiguate get the size of *Ptr.<br>
> - uint64_t AccessSize = 0;<br>
> - if (AA) {<br>
> - Type *AccessTy = cast<PointerType>(Ptr->getType())->getElementType();<br>
> - AccessSize = AA->getTypeStoreSize(AccessTy);<br>
> - }<br>
> + uint64_t AccessSize = AA ? AA->getTypeStoreSize(AccessTy) : 0;<br>
> +<br>
> + Value *StrippedPtr = Ptr->stripPointerCasts();<br>
><br>
> while (ScanFrom != ScanBB->begin()) {<br>
> // We must ignore debug info directives when counting (otherwise they<br>
> @@ -183,17 +200,21 @@ Value *llvm::FindAvailableLoadedValue(Va<br>
> // (This is true even if the load is volatile or atomic, although<br>
> // those cases are unlikely.)<br>
> if (LoadInst *LI = dyn_cast<LoadInst>(Inst))<br>
> - if (AreEquivalentAddressValues(LI->getOperand(0), Ptr)) {<br>
> + if (AreEquivalentAddressValues(<br>
> + LI->getPointerOperand()->stripPointerCasts(), StrippedPtr) &&<br>
> + CastInst::isBitCastable(LI->getType(), AccessTy)) {<br>
> if (AATags)<br>
> LI->getAAMetadata(*AATags);<br>
> return LI;<br>
> }<br>
><br>
> if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) {<br>
> + Value *StorePtr = SI->getPointerOperand()->stripPointerCasts();<br>
> // If this is a store through Ptr, the value is available!<br>
> // (This is true even if the store is volatile or atomic, although<br>
> // those cases are unlikely.)<br>
> - if (AreEquivalentAddressValues(SI->getOperand(1), Ptr)) {<br>
> + if (AreEquivalentAddressValues(StorePtr, StrippedPtr) &&<br>
> + CastInst::isBitCastable(SI->getValueOperand()->getType(), AccessTy)) {<br>
> if (AATags)<br>
> SI->getAAMetadata(*AATags);<br>
> return SI->getOperand(0);<br>
> @@ -202,15 +223,15 @@ Value *llvm::FindAvailableLoadedValue(Va<br>
> // If Ptr is an alloca and this is a store to a different alloca, ignore<br>
> // the store. This is a trivial form of alias analysis that is important<br>
> // for reg2mem'd code.<br>
> - if ((isa<AllocaInst>(Ptr) || isa<GlobalVariable>(Ptr)) &&<br>
> - (isa<AllocaInst>(SI->getOperand(1)) ||<br>
> - isa<GlobalVariable>(SI->getOperand(1))))<br>
> + if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&<br>
> + (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)))<br>
> continue;<br>
><br>
> // If we have alias analysis and it says the store won't modify the loaded<br>
> // value, ignore the store.<br>
> if (AA &&<br>
> - (AA->getModRefInfo(SI, Ptr, AccessSize) & AliasAnalysis::Mod) == 0)<br>
> + (AA->getModRefInfo(SI, StrippedPtr, AccessSize) &<br>
> + AliasAnalysis::Mod) == 0)<br>
> continue;<br>
><br>
> // Otherwise the store that may or may not alias the pointer, bail out.<br>
> @@ -223,7 +244,8 @@ Value *llvm::FindAvailableLoadedValue(Va<br>
> // If alias analysis claims that it really won't modify the load,<br>
> // ignore it.<br>
> if (AA &&<br>
> - (AA->getModRefInfo(Inst, Ptr, AccessSize) & AliasAnalysis::Mod) == 0)<br>
> + (AA->getModRefInfo(Inst, StrippedPtr, AccessSize) &<br>
> + AliasAnalysis::Mod) == 0)<br>
> continue;<br>
><br>
> // May modify the pointer, bail out.<br>
><br>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=220178&r1=220177&r2=220178&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=220178&r1=220177&r2=220178&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Sun Oct 19 19:24:14 2014<br>
> @@ -420,7 +420,8 @@ Instruction *InstCombiner::visitLoadInst<br>
> // separated by a few arithmetic operations.<br>
> BasicBlock::iterator BBI = &LI;<br>
> if (Value *AvailableVal = FindAvailableLoadedValue(Op, LI.getParent(), BBI,6))<br>
> - return ReplaceInstUsesWith(LI, AvailableVal);<br>
> + return ReplaceInstUsesWith(<br>
> + LI, Builder->CreateBitCast(AvailableVal, LI.getType()));<br>
><br>
> // load(gep null, ...) -> unreachable<br>
> if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(Op)) {<br>
><br>
> Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=220178&r1=220177&r2=220178&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=220178&r1=220177&r2=220178&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)<br>
> +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Sun Oct 19 19:24:14 2014<br>
> @@ -901,6 +901,9 @@ bool JumpThreading::SimplifyPartiallyRed<br>
> // If the returned value is the load itself, replace with an undef. This can<br>
> // only happen in dead loops.<br>
> if (AvailableVal == LI) AvailableVal = UndefValue::get(LI->getType());<br>
> + if (AvailableVal->getType() != LI->getType())<br>
> + AvailableVal = CastInst::Create(CastInst::BitCast, AvailableVal,<br>
> + LI->getType(), "", LI);<br>
> LI->replaceAllUsesWith(AvailableVal);<br>
> LI->eraseFromParent();<br>
> return true;<br>
> @@ -1031,7 +1034,13 @@ bool JumpThreading::SimplifyPartiallyRed<br>
> assert(I != AvailablePreds.end() && I->first == P &&<br>
> "Didn't find entry for predecessor!");<br>
><br>
> - PN->addIncoming(I->second, I->first);<br>
> + // If we have an available predecessor but it requires casting, insert the<br>
> + // cast in the predecessor and use the cast.<br>
> + Value *PredV = I->second;<br>
> + if (PredV->getType() != LI->getType())<br>
> + PredV = CastInst::Create(CastInst::BitCast, PredV, LI->getType(), "", P);<br>
> +<br>
> + PN->addIncoming(PredV, I->first);<br>
> }<br>
><br>
> //cerr << "PRE: " << *LI << *PN << "\n";<br>
><br>
> Modified: llvm/trunk/test/Transforms/InstCombine/select.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=220178&r1=220177&r2=220178&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=220178&r1=220177&r2=220178&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Transforms/InstCombine/select.ll (original)<br>
> +++ llvm/trunk/test/Transforms/InstCombine/select.ll Sun Oct 19 19:24:14 2014<br>
> @@ -1276,3 +1276,112 @@ define i32 @test77(i1 %flag, i32* %x) {<br>
> %v = load i32* %p<br>
> ret i32 %v<br>
> }<br>
> +<br>
> +define i32 @test78(i1 %flag, i32* %x, i32* %y, i32* %z) {<br>
> +; Test that we can speculate the loads around the select even when we can't<br>
> +; fold the load completely away.<br>
> +; CHECK-LABEL: @test78(<br>
> +; CHECK: %[[V1:.*]] = load i32* %x<br>
> +; CHECK-NEXT: %[[V2:.*]] = load i32* %y<br>
> +; CHECK-NEXT: %[[S:.*]] = select i1 %flag, i32 %[[V1]], i32 %[[V2]]<br>
> +; CHECK-NEXT: ret i32 %[[S]]<br>
> +entry:<br>
> + store i32 0, i32* %x<br>
> + store i32 0, i32* %y<br>
> + ; Block forwarding by storing to %z which could alias either %x or %y.<br>
> + store i32 42, i32* %z<br>
> + %p = select i1 %flag, i32* %x, i32* %y<br>
> + %v = load i32* %p<br>
> + ret i32 %v<br>
> +}<br>
> +<br>
> +define float @test79(i1 %flag, float* %x, i32* %y, i32* %z) {<br>
> +; Test that we can speculate the loads around the select even when we can't<br>
> +; fold the load completely away.<br>
> +; CHECK-LABEL: @test79(<br>
> +; CHECK: %[[V1:.*]] = load float* %x<br>
> +; CHECK-NEXT: %[[V2:.*]] = load float* %y<br>
> +; CHECK-NEXT: %[[S:.*]] = select i1 %flag, float %[[V1]], float %[[V2]]<br>
> +; CHECK-NEXT: ret float %[[S]]<br>
> +entry:<br>
> + %x1 = bitcast float* %x to i32*<br>
> + %y1 = bitcast i32* %y to float*<br>
> + store i32 0, i32* %x1<br>
> + store i32 0, i32* %y<br>
> + ; Block forwarding by storing to %z which could alias either %x or %y.<br>
> + store i32 42, i32* %z<br>
> + %p = select i1 %flag, float* %x, float* %y1<br>
> + %v = load float* %p<br>
> + ret float %v<br>
> +}<br>
> +<br>
> +define i32 @test80(i1 %flag) {<br>
> +; Test that when we speculate the loads around the select they fold throug<br>
> +; load->load folding and load->store folding.<br>
> +; CHECK-LABEL: @test80(<br>
> +; CHECK: %[[X:.*]] = alloca i32<br>
> +; CHECK-NEXT: %[[Y:.*]] = alloca i32<br>
> +; CHECK: %[[V:.*]] = load i32* %[[X]]<br>
> +; CHECK-NEXT: store i32 %[[V]], i32* %[[Y]]<br>
> +; CHECK-NEXT: ret i32 %[[V]]<br>
> +entry:<br>
> + %x = alloca i32<br>
> + %y = alloca i32<br>
> + call void @scribble_on_memory(i32* %x)<br>
> + call void @scribble_on_memory(i32* %y)<br>
> + %tmp = load i32* %x<br>
> + store i32 %tmp, i32* %y<br>
> + %p = select i1 %flag, i32* %x, i32* %y<br>
> + %v = load i32* %p<br>
> + ret i32 %v<br>
> +}<br>
> +<br>
> +define float @test81(i1 %flag) {<br>
> +; Test that we can speculate the load around the select even though they use<br>
> +; differently typed pointers.<br>
> +; CHECK-LABEL: @test81(<br>
> +; CHECK: %[[X:.*]] = alloca i32<br>
> +; CHECK-NEXT: %[[Y:.*]] = alloca i32<br>
> +; CHECK: %[[V:.*]] = load i32* %[[X]]<br>
> +; CHECK-NEXT: store i32 %[[V]], i32* %[[Y]]<br>
> +; CHECK-NEXT: %[[C:.*]] = bitcast i32 %[[V]] to float<br>
> +; CHECK-NEXT: ret float %[[C]]<br>
> +entry:<br>
> + %x = alloca float<br>
> + %y = alloca i32<br>
> + %x1 = bitcast float* %x to i32*<br>
> + %y1 = bitcast i32* %y to float*<br>
> + call void @scribble_on_memory(i32* %x1)<br>
> + call void @scribble_on_memory(i32* %y)<br>
> + %tmp = load i32* %x1<br>
> + store i32 %tmp, i32* %y<br>
> + %p = select i1 %flag, float* %x, float* %y1<br>
> + %v = load float* %p<br>
> + ret float %v<br>
> +}<br>
> +<br>
> +define i32 @test82(i1 %flag) {<br>
> +; Test that we can speculate the load around the select even though they use<br>
> +; differently typed pointers.<br>
> +; CHECK-LABEL: @test82(<br>
> +; CHECK: %[[X:.*]] = alloca float<br>
> +; CHECK-NEXT: %[[Y:.*]] = alloca i32<br>
> +; CHECK-NEXT: %[[X1:.*]] = bitcast float* %[[X]] to i32*<br>
> +; CHECK-NEXT: %[[Y1:.*]] = bitcast i32* %[[Y]] to float*<br>
> +; CHECK: %[[V:.*]] = load float* %[[X]]<br>
> +; CHECK-NEXT: store float %[[V]], float* %[[Y1]]<br>
> +; CHECK-NEXT: %[[C:.*]] = bitcast float %[[V]] to i32<br>
> +; CHECK-NEXT: ret i32 %[[C]]<br>
> +entry:<br>
> + %x = alloca float<br>
> + %y = alloca i32<br>
> + %x1 = bitcast float* %x to i32*<br>
> + %y1 = bitcast i32* %y to float*<br>
> + call void @scribble_on_memory(i32* %x1)<br>
> + call void @scribble_on_memory(i32* %y)<br>
> + %tmp = load float* %x<br>
> + store float %tmp, float* %y1<br>
> + %p = select i1 %flag, i32* %x1, i32* %y<br>
> + %v = load i32* %p<br>
> + ret i32 %v<br>
> +}<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>