[LICM] Make isGuaranteedToExecute more accurate.
Summary:
Make isGuaranteedToExecute use the
isGuaranteedToTransferExecutionToSuccessor helper, and make that helper
a bit more accurate.
There's a potential performance impact here from assuming that arbitrary
calls might not return. This probably has little impact on loads and
stores to a pointer because most things alias analysis can reason about
are dereferenceable anyway. The other impacts, like less aggressive
hoisting of sdiv by a variable and less aggressive hoisting around
volatile memory operations, are unlikely to matter for real code.
This also impacts SCEV, which uses the same helper. It's a minor
improvement there because we can tell that, for example, memcpy always
returns normally. Strictly speaking, it's also introducing
a bug, but it's not any worse than everywhere else we assume readonly
functions terminate.
Fixes http://llvm.org/PR27857.
Reviewers: hfinkel, reames, chandlerc, sanjoy
Subscribers: broune, llvm-commits
Differential Revision: http://reviews.llvm.org/D21167
llvm-svn: 272489
2016-06-12 05:48:25 +08:00
|
|
|
; RUN: opt -S -basicaa -licm < %s | FileCheck %s
|
2016-07-13 06:37:48 +08:00
|
|
|
; RUN: opt -aa-pipeline=basic-aa -passes='lcssa,require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' -S %s | FileCheck %s
|
[LICM] Make isGuaranteedToExecute more accurate.
Summary:
Make isGuaranteedToExecute use the
isGuaranteedToTransferExecutionToSuccessor helper, and make that helper
a bit more accurate.
There's a potential performance impact here from assuming that arbitrary
calls might not return. This probably has little impact on loads and
stores to a pointer because most things alias analysis can reason about
are dereferenceable anyway. The other impacts, like less aggressive
hoisting of sdiv by a variable and less aggressive hoisting around
volatile memory operations, are unlikely to matter for real code.
This also impacts SCEV, which uses the same helper. It's a minor
improvement there because we can tell that, for example, memcpy always
returns normally. Strictly speaking, it's also introducing
a bug, but it's not any worse than everywhere else we assume readonly
functions terminate.
Fixes http://llvm.org/PR27857.
Reviewers: hfinkel, reames, chandlerc, sanjoy
Subscribers: broune, llvm-commits
Differential Revision: http://reviews.llvm.org/D21167
llvm-svn: 272489
2016-06-12 05:48:25 +08:00
|
|
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
target triple = "x86_64-unknown-linux-gnu"
|
|
|
|
|
|
|
|
declare void @f() nounwind
|
|
|
|
|
|
|
|
; Don't hoist load past nounwind call.
|
|
|
|
define i32 @test1(i32* noalias nocapture readonly %a) nounwind uwtable {
|
|
|
|
; CHECK-LABEL: @test1(
|
|
|
|
entry:
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
; CHECK: tail call void @f()
|
|
|
|
; CHECK-NEXT: load i32
|
|
|
|
for.body:
|
|
|
|
%i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
|
|
|
%x.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
|
|
|
|
tail call void @f() nounwind
|
|
|
|
%i1 = load i32, i32* %a, align 4
|
|
|
|
%add = add nsw i32 %i1, %x.05
|
|
|
|
%inc = add nuw nsw i32 %i.06, 1
|
|
|
|
%exitcond = icmp eq i32 %inc, 1000
|
|
|
|
br i1 %exitcond, label %for.cond.cleanup, label %for.body
|
|
|
|
|
|
|
|
for.cond.cleanup:
|
|
|
|
ret i32 %add
|
|
|
|
}
|
|
|
|
|
|
|
|
; Don't hoist division past nounwind call.
|
|
|
|
define i32 @test2(i32 %N, i32 %c) nounwind uwtable {
|
|
|
|
; CHECK-LABEL: @test2(
|
|
|
|
entry:
|
|
|
|
%cmp4 = icmp sgt i32 %N, 0
|
|
|
|
br i1 %cmp4, label %for.body, label %for.cond.cleanup
|
|
|
|
|
|
|
|
; CHECK: tail call void @f()
|
|
|
|
; CHECK-NEXT: sdiv i32
|
|
|
|
for.body:
|
|
|
|
%i.05 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
|
|
|
|
tail call void @f() nounwind
|
|
|
|
%div = sdiv i32 5, %c
|
|
|
|
%add = add i32 %i.05, 1
|
|
|
|
%inc = add i32 %add, %div
|
|
|
|
%cmp = icmp slt i32 %inc, %N
|
|
|
|
br i1 %cmp, label %for.body, label %for.cond.cleanup
|
|
|
|
|
|
|
|
for.cond.cleanup:
|
|
|
|
ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
; Don't hoist load past volatile load.
|
|
|
|
define i32 @test3(i32* noalias nocapture readonly %a, i32* %v) nounwind uwtable {
|
|
|
|
; CHECK-LABEL: @test3(
|
|
|
|
entry:
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
; CHECK: load volatile i32
|
|
|
|
; CHECK-NEXT: load i32
|
|
|
|
for.body:
|
|
|
|
%i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
|
|
|
%x.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
|
|
|
|
%xxx = load volatile i32, i32* %v, align 4
|
|
|
|
%i1 = load i32, i32* %a, align 4
|
|
|
|
%add = add nsw i32 %i1, %x.05
|
|
|
|
%inc = add nuw nsw i32 %i.06, 1
|
|
|
|
%exitcond = icmp eq i32 %inc, 1000
|
|
|
|
br i1 %exitcond, label %for.cond.cleanup, label %for.body
|
|
|
|
|
|
|
|
for.cond.cleanup:
|
|
|
|
ret i32 %add
|
|
|
|
}
|