diff options
| author | Hal Finkel <hfinkel@anl.gov> | 2014-11-03 23:19:16 +0000 |
|---|---|---|
| committer | Hal Finkel <hfinkel@anl.gov> | 2014-11-03 23:19:16 +0000 |
| commit | 840257a49c26c5c7d66ee17eeaaf5a43fad0b9da (patch) | |
| tree | eda3b865cc17c5c710a5b6e8fe79d62e24a2b9e4 /llvm/test/Transforms/LoadCombine | |
| parent | 5b02a19f909bf7610c629ac1f16e79bd88a3d442 (diff) | |
| download | bcm5719-llvm-840257a49c26c5c7d66ee17eeaaf5a43fad0b9da.tar.gz bcm5719-llvm-840257a49c26c5c7d66ee17eeaaf5a43fad0b9da.zip | |
Use AA in LoadCombine
LoadCombine can be smarter about aborting when a writing instruction is
encountered, instead of aborting upon encountering any writing instruction, use
an AliasSetTracker, and only abort when encountering some write that might
alias with the loads that could potentially be combined.
This was originally motivated by comments made (and a test case provided) by
David Majnemer in response to PR21448. It turned out that LoadCombine was not
responsible for that PR, but LoadCombine should also be improved so that
unrelated stores (and @llvm.assume) don't interrupt load combining.
llvm-svn: 221203
Diffstat (limited to 'llvm/test/Transforms/LoadCombine')
| -rw-r--r-- | llvm/test/Transforms/LoadCombine/load-combine-aa.ll | 39 | ||||
| -rw-r--r-- | llvm/test/Transforms/LoadCombine/load-combine-assume.ll | 44 |
2 files changed, 83 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoadCombine/load-combine-aa.ll b/llvm/test/Transforms/LoadCombine/load-combine-aa.ll new file mode 100644 index 00000000000..3542dcebf5e --- /dev/null +++ b/llvm/test/Transforms/LoadCombine/load-combine-aa.ll @@ -0,0 +1,39 @@ +; RUN: opt -basicaa -load-combine -instcombine -S < %s | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define i64 @test1(i32* nocapture readonly noalias %a, i32* nocapture readonly noalias %b) { +; CHECK-LABEL: @test1 + +; CHECK: load i64* +; CHECK: ret i64 + + %load1 = load i32* %a, align 4 + %conv = zext i32 %load1 to i64 + %arrayidx1 = getelementptr inbounds i32* %a, i64 1 + store i32 %load1, i32* %b, align 4 + %load2 = load i32* %arrayidx1, align 4 + %conv2 = zext i32 %load2 to i64 + %shl = shl nuw i64 %conv2, 32 + %add = or i64 %shl, %conv + ret i64 %add +} + +define i64 @test2(i32* nocapture readonly %a, i32* nocapture readonly %b) { +; CHECK-LABEL: @test2 + +; CHECK: load i32* +; CHECK: load i32* +; CHECK: ret i64 + + %load1 = load i32* %a, align 4 + %conv = zext i32 %load1 to i64 + %arrayidx1 = getelementptr inbounds i32* %a, i64 1 + store i32 %load1, i32* %b, align 4 + %load2 = load i32* %arrayidx1, align 4 + %conv2 = zext i32 %load2 to i64 + %shl = shl nuw i64 %conv2, 32 + %add = or i64 %shl, %conv + ret i64 %add +} + diff --git a/llvm/test/Transforms/LoadCombine/load-combine-assume.ll b/llvm/test/Transforms/LoadCombine/load-combine-assume.ll new file mode 100644 index 00000000000..94f630072ad --- /dev/null +++ b/llvm/test/Transforms/LoadCombine/load-combine-assume.ll @@ -0,0 +1,44 @@ +; RUN: opt -basicaa -load-combine -instcombine -S < %s | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare void @llvm.assume(i1) nounwind + +; 'load' before the 'call' gets optimized: +define i64 @test1(i32* nocapture readonly %a, i1 %b) { +; CHECK-LABEL: @test1 + +; CHECK-DAG: load i64* %1, align 4 +; CHECK-DAG: tail call void @llvm.assume(i1 %b) +; CHECK: ret i64 + + %load1 = load i32* %a, align 4 + %conv = zext i32 %load1 to i64 + %arrayidx1 = getelementptr inbounds i32* %a, i64 1 + %load2 = load i32* %arrayidx1, align 4 + tail call void @llvm.assume(i1 %b) + %conv2 = zext i32 %load2 to i64 + %shl = shl nuw i64 %conv2, 32 + %add = or i64 %shl, %conv + ret i64 %add +} + +; 'call' before the 'load' doesn't get optimized: +define i64 @test2(i32* nocapture readonly %a, i1 %b) { +; CHECK-LABEL: @test2 + +; CHECK-DAG: load i64* %1, align 4 +; CHECK-DAG: tail call void @llvm.assume(i1 %b) +; CHECK: ret i64 + + %load1 = load i32* %a, align 4 + %conv = zext i32 %load1 to i64 + %arrayidx1 = getelementptr inbounds i32* %a, i64 1 + tail call void @llvm.assume(i1 %b) + %load2 = load i32* %arrayidx1, align 4 + %conv2 = zext i32 %load2 to i64 + %shl = shl nuw i64 %conv2, 32 + %add = or i64 %shl, %conv + ret i64 %add +} + |

