[llvm] [GVN] Drop Clobber dependency if store may overwrite only the same value (PR #68322)
Sergey Kachkov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 05:17:56 PDT 2023
================
@@ -0,0 +1,91 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
+; RUN: opt < %s -passes=gvn -S | FileCheck %s
+
+define void @test_i8(ptr %a, ptr %b, ptr %c) {
+; CHECK-LABEL: define void @test_i8(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[A]], align 1
+; CHECK-NEXT: store i8 [[TMP0]], ptr [[B]], align 1
+; CHECK-NEXT: store i8 [[TMP0]], ptr [[C]], align 1
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = load i8, ptr %a, align 1
+ store i8 %0, ptr %b, align 1
+ %1 = load i8, ptr %a, align 1
+ store i8 %1, ptr %c, align 1
+ ret void
+}
+
+define void @test_i32(ptr %a, ptr %b, ptr %c) {
+; CHECK-LABEL: define void @test_i32(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[A]], align 4
+; CHECK-NEXT: store i32 [[TMP0]], ptr [[B]], align 4
+; CHECK-NEXT: store i32 [[TMP0]], ptr [[C]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = load i32, ptr %a, align 4
+ store i32 %0, ptr %b, align 4
+ %1 = load i32, ptr %a, align 4
+ store i32 %1, ptr %c, align 4
+ ret void
+}
+
+define void @test_float(ptr %a, ptr %b, ptr %c) {
+; CHECK-LABEL: define void @test_float(
+; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = load float, ptr [[A]], align 4
+; CHECK-NEXT: store float [[TMP0]], ptr [[B]], align 4
+; CHECK-NEXT: store float [[TMP0]], ptr [[C]], align 4
+; CHECK-NEXT: ret void
+;
+entry:
+ %0 = load float, ptr %a, align 4
+ store float %0, ptr %b, align 4
+ %1 = load float, ptr %a, align 4
+ store float %1, ptr %c, align 4
+ ret void
+}
----------------
skachkov-sc wrote:
Added test_i1, I think that we shouldn't have any problems with it, because the only relevant information for this optimization is the location size (not loaded/stored type), and for i1 the location size will be DataLayout::getTypeStoreSize(i1), which is something like 1 byte in most cases, so this test should be optimized very similarly to test_i8.
https://github.com/llvm/llvm-project/pull/68322
More information about the llvm-commits
mailing list