]> granicus.if.org Git - llvm/commitdiff
[ValueTracking] Calls to @llvm.assume always return
authorSanjoy Das <sanjoy@playingwithpointers.com>
Tue, 14 Jun 2016 20:23:16 +0000 (20:23 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Tue, 14 Jun 2016 20:23:16 +0000 (20:23 +0000)
This change teaches llvm::isGuaranteedToTransferExecutionToSuccessor
that calls to @llvm.assume always terminate.  Most other relevant
intrinsics should be covered by the "CS.onlyReadsMemory() ||
CS.onlyAccessesArgMemory()" bit but we were missing @llvm.assumes
because we state that it clobbers memory.

Added an LICM test case, but this change is not specific to LICM.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272703 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ValueTracking.cpp
test/Transforms/LICM/assume.ll

index 7e09ec74befdfd6eac974ba6bda0688dd7822b8f..7109ff84b8e41830decba7cae17e3655400cfee7 100644 (file)
@@ -3478,7 +3478,8 @@ bool llvm::isGuaranteedToTransferExecutionToSuccessor(const Instruction *I) {
     // but it's consistent with other passes. See http://llvm.org/PR965 .
     // FIXME: This isn't aggressive enough; a call which only writes to a
     // global is guaranteed to return.
-    return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory();
+    return CS.onlyReadsMemory() || CS.onlyAccessesArgMemory() ||
+           match(I, m_Intrinsic<Intrinsic::assume>());
   }
 
   // Other instructions return normally.
index 9abf5578287aecee1ee31c5077c68c600f92b957..e426350ce73595488dc17efb94cc9e223c1ef75c 100644 (file)
@@ -1,6 +1,7 @@
 ; RUN: opt -licm -basicaa < %s -S | FileCheck %s
 
-define void @f(i1 %p) nounwind ssp {
+define void @f_0(i1 %p) nounwind ssp {
+; CHECK-LABEL: @f_0(
 entry:
   br label %for.body
 
@@ -31,4 +32,20 @@ for.end104:
   ret void
 }
 
+define void @f_1(i1 %cond, i32* %ptr) {
+; CHECK-LABEL: @f_1(
+; CHECK: %val = load i32, i32* %ptr
+; CHECK-NEXT:  br label %loop
+
+entry:
+  br label %loop
+
+loop:
+  %x = phi i32 [ 0, %entry ], [ %x.inc, %loop ]
+  call void @llvm.assume(i1 %cond)
+  %val = load i32, i32* %ptr
+  %x.inc = add i32 %x, %val
+  br label %loop
+}
+
 declare void @llvm.assume(i1)