[llvm] r339936 - [MemLoc] Fix a bug causing any use of invariant.end to crash in LICM

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 16 13:48:55 PDT 2018


Author: reames
Date: Thu Aug 16 13:48:55 2018
New Revision: 339936

URL: http://llvm.org/viewvc/llvm-project?rev=339936&view=rev
Log:
[MemLoc] Fix a bug causing any use of invariant.end to crash in LICM

The fix is fairly simple, but is says something unpleasant about the usage and testing of invariant.start/end scopes that this went undetected.  To put this in perspective, *any* invariant.end in a loop flowing through LICM crashed.  I haven't bothered to figure out just how far back this goes, but it's not caused by any of the recent changes.  We're probably talking months if not years.  


Modified:
    llvm/trunk/lib/Analysis/MemoryLocation.cpp
    llvm/trunk/test/Transforms/LICM/invariant.start.ll

Modified: llvm/trunk/lib/Analysis/MemoryLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryLocation.cpp?rev=339936&r1=339935&r2=339936&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryLocation.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryLocation.cpp Thu Aug 16 13:48:55 2018
@@ -137,6 +137,10 @@ MemoryLocation MemoryLocation::getForArg
           Arg, cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(), AATags);
 
     case Intrinsic::invariant_end:
+      // The first argument to an invariant.end is a "descriptor" type (e.g. a
+      // pointer to a empty struct) which is never actually dereferenced.
+      if (ArgIdx == 0)
+        return MemoryLocation(Arg, 0, AATags);
       assert(ArgIdx == 2 && "Invalid argument index");
       return MemoryLocation(
           Arg, cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(), AATags);

Modified: llvm/trunk/test/Transforms/LICM/invariant.start.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/invariant.start.ll?rev=339936&r1=339935&r2=339936&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LICM/invariant.start.ll (original)
+++ llvm/trunk/test/Transforms/LICM/invariant.start.ll Thu Aug 16 13:48:55 2018
@@ -101,9 +101,7 @@ loop:
   store i32 0, i32* %ptr
   %scope = call {}* @llvm.invariant.start.p0i32(i64 4, i32* %ptr)
   %val = load i32, i32* %ptr
-;;  NOTE: despite being correct syntax, uncommenting this line causes
-;;  a crash in the optimizer.  FIXME
-;;  call void @llvm.invariant.end.p0i32({}* %scope, i64 4, i32* %ptr)
+  call void @llvm.invariant.end.p0i32({}* %scope, i64 4, i32* %ptr)
   %x.inc = add i32 %x, %val
   br label %loop
 }




More information about the llvm-commits mailing list