[llvm] 7081db9 - [DSE] Add tests with noalias store between noop load/store.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 18 02:43:57 PDT 2020
Author: Florian Hahn
Date: 2020-10-18T10:43:24+01:00
New Revision: 7081db99eee0123f955ab01e550bdfdfce606dd2
URL: https://github.com/llvm/llvm-project/commit/7081db99eee0123f955ab01e550bdfdfce606dd2
DIFF: https://github.com/llvm/llvm-project/commit/7081db99eee0123f955ab01e550bdfdfce606dd2.diff
LOG: [DSE] Add tests with noalias store between noop load/store.
This adds 2 new tests from PR47887 and regenerates the check lines for
the file.
Added:
Modified:
llvm/test/Transforms/DeadStoreElimination/MSSA/noop-stores.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/noop-stores.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/noop-stores.ll
index f74b9d184921..22bf3951e4db 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/noop-stores.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/noop-stores.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -S | FileCheck %s
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
@@ -13,8 +14,8 @@ declare void @llvm.init.trampoline(i8*, i8*, i8*)
; We CAN optimize volatile loads.
define void @test_load_volatile(i32* %Q) {
; CHECK-LABEL: @test_load_volatile(
-; CHECK-NEXT: [[A:%.*]] = load volatile i32, i32* [[Q:%.*]]
-; CHECK-NEXT: store i32 [[A]], i32* [[Q]]
+; CHECK-NEXT: [[A:%.*]] = load volatile i32, i32* [[Q:%.*]], align 4
+; CHECK-NEXT: store i32 [[A]], i32* [[Q]], align 4
; CHECK-NEXT: ret void
;
%a = load volatile i32, i32* %Q
@@ -25,8 +26,8 @@ define void @test_load_volatile(i32* %Q) {
; We can NOT optimize volatile stores.
define void @test_store_volatile(i32* %Q) {
; CHECK-LABEL: @test_store_volatile(
-; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]]
-; CHECK-NEXT: store volatile i32 [[A]]
+; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
+; CHECK-NEXT: store volatile i32 [[A]], i32* [[Q]], align 4
; CHECK-NEXT: ret void
;
%a = load i32, i32* %Q
@@ -124,10 +125,17 @@ bb2:
; Don't remove "redundant" store if %p is possibly stored to.
define i32 @test46(i1 %c, i32* %p, i32* %p2, i32 %i) {
; CHECK-LABEL: @test46(
-; CHECK: load
-; CHECK: store
-; CHECK: store
-; CHECK: ret i32 0
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
+; CHECK-NEXT: br label [[BB1:%.*]]
+; CHECK: bb1:
+; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
+; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
+; CHECK: bb2:
+; CHECK-NEXT: store i32 0, i32* [[P2:%.*]], align 4
+; CHECK-NEXT: br i1 [[C]], label [[BB3:%.*]], label [[BB1]]
+; CHECK: bb3:
+; CHECK-NEXT: ret i32 0
;
entry:
%v = load i32, i32* %p, align 4
@@ -176,9 +184,9 @@ declare void @unkown_write(i32*)
; We can't remove the "noop" store around an unkown write.
define void @test43(i32* %Q) {
; CHECK-LABEL: @test43(
-; CHECK-NEXT: load
-; CHECK-NEXT: call
-; CHECK-NEXT: store
+; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
+; CHECK-NEXT: call void @unkown_write(i32* [[Q]])
+; CHECK-NEXT: store i32 [[A]], i32* [[Q]], align 4
; CHECK-NEXT: ret void
;
%a = load i32, i32* %Q
@@ -190,8 +198,9 @@ define void @test43(i32* %Q) {
; We CAN remove it when the unkown write comes AFTER.
define void @test44(i32* %Q) {
; CHECK-LABEL: @test44(
-; CHECK-NEXT: call
+; CHECK-NEXT: call void @unkown_write(i32* [[Q:%.*]])
; CHECK-NEXT: ret void
+;
%a = load i32, i32* %Q
store i32 %a, i32* %Q
call void @unkown_write(i32* %Q)
@@ -200,9 +209,10 @@ define void @test44(i32* %Q) {
define void @test45(i32* %Q) {
; CHECK-LABEL: @test45(
-; CHECK-NEXT: [[A:%.*]] = load
-; CHECK-NEXT: store i32 [[A]]
+; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
+; CHECK-NEXT: store i32 [[A]], i32* [[Q]], align 4
; CHECK-NEXT: ret void
+;
%a = load i32, i32* %Q
store i32 10, i32* %Q
store i32 %a, i32* %Q
@@ -211,11 +221,20 @@ define void @test45(i32* %Q) {
define i32 @test48(i1 %c, i32* %p) {
; CHECK-LABEL: @test48(
-; CHECK: entry:
-; CHECK-NEXT: [[V:%.*]] = load
-; CHECK: store i32 0
-; CHECK: store i32 [[V]]
-; CHECK: ret i32 0
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
+; CHECK-NEXT: br i1 [[C:%.*]], label [[BB0:%.*]], label [[BB0_0:%.*]]
+; CHECK: bb0:
+; CHECK-NEXT: store i32 0, i32* [[P]], align 4
+; CHECK-NEXT: br i1 [[C]], label [[BB1:%.*]], label [[BB2:%.*]]
+; CHECK: bb0.0:
+; CHECK-NEXT: br label [[BB1]]
+; CHECK: bb1:
+; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
+; CHECK-NEXT: br i1 [[C]], label [[BB2]], label [[BB0]]
+; CHECK: bb2:
+; CHECK-NEXT: ret i32 0
+;
entry:
%v = load i32, i32* %p, align 4
br i1 %c, label %bb0, label %bb0.0
@@ -236,15 +255,18 @@ bb2:
; TODO: Remove both redundant stores if loaded value is in another block inside a loop.
define i32 @test47(i1 %c, i32* %p, i32 %i) {
-; X-CHECK-LABEL: @test47(
-; X-CHECK-NEXT: entry:
-; X-CHECK-NEXT: br label [[BB1:%.*]]
-; X-CHECK: bb1:
-; X-CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
-; X-CHECK: bb2:
-; X-CHECK-NEXT: br i1 [[C]], label [[BB2]], label [[BB3:%.*]]
-; X-CHECK: bb3:
-; X-CHECK-NEXT: ret i32 0
+; CHECK-LABEL: @test47(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
+; CHECK-NEXT: br label [[BB1:%.*]]
+; CHECK: bb1:
+; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
+; CHECK: bb2:
+; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
+; CHECK-NEXT: br i1 [[C]], label [[BB3:%.*]], label [[BB1]]
+; CHECK: bb3:
+; CHECK-NEXT: ret i32 0
+;
entry:
%v = load i32, i32* %p, align 4
br label %bb1
@@ -258,3 +280,38 @@ bb3:
ret i32 0
}
+; Test case from PR47887.
+define void @test_noalias_store_between_load_and_store(i32* noalias %x, i32* noalias %y) {
+; CHECK-LABEL: @test_noalias_store_between_load_and_store(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[X:%.*]], align 4
+; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
+; CHECK-NEXT: store i32 [[LV]], i32* [[X]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %lv = load i32, i32* %x, align 4
+ store i32 0, i32* %y, align 4
+ store i32 %lv, i32* %x, align 4
+ ret void
+}
+
+; Test case from PR47887. Currently we eliminate the dead `store i32 %inc, i32* %x`,
+; but not the no-op `store i32 %lv, i32* %x`. That is because no-op stores are
+; eliminated before dead stores for the same def.
+define void @test_noalias_store_between_load_and_store_elimin_order(i32* noalias %x, i32* noalias %y) {
+; CHECK-LABEL: @test_noalias_store_between_load_and_store_elimin_order(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[X:%.*]], align 4
+; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
+; CHECK-NEXT: store i32 [[LV]], i32* [[X]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %lv = load i32, i32* %x, align 4
+ %inc = add nsw i32 %lv, 1
+ store i32 %inc, i32* %x, align 4
+ store i32 0, i32* %y, align 4
+ store i32 %lv, i32* %x, align 4
+ ret void
+}
More information about the llvm-commits
mailing list