[llvm] 8242bd1 - [EarlyCSE] Add tests showing loss of alignment info for ptr loads.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 11:34:33 PDT 2024
Author: Florian Hahn
Date: 2024-09-19T19:33:58+01:00
New Revision: 8242bd116d547cbebe0102cda1c4421ee4865407
URL: https://github.com/llvm/llvm-project/commit/8242bd116d547cbebe0102cda1c4421ee4865407
DIFF: https://github.com/llvm/llvm-project/commit/8242bd116d547cbebe0102cda1c4421ee4865407.diff
LOG: [EarlyCSE] Add tests showing loss of alignment info for ptr loads.
Precommit tests for https://github.com/llvm/llvm-project/pull/109131.
Added:
llvm/test/Transforms/EarlyCSE/materialize-align-assumptions.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/EarlyCSE/materialize-align-assumptions.ll b/llvm/test/Transforms/EarlyCSE/materialize-align-assumptions.ll
new file mode 100644
index 00000000000000..ea63376957162b
--- /dev/null
+++ b/llvm/test/Transforms/EarlyCSE/materialize-align-assumptions.ll
@@ -0,0 +1,100 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes='early-cse<memssa>' -S %s | FileCheck %s
+
+declare void @foo(ptr)
+
+define ptr @align_replacement_does_not_have_align_metadata(ptr noalias %p) {
+; CHECK-LABEL: define ptr @align_replacement_does_not_have_align_metadata(
+; CHECK-SAME: ptr noalias [[P:%.*]]) {
+; CHECK-NEXT: [[L_1:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-NEXT: call void @foo(ptr [[L_1]])
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[L_1]], i64 4
+; CHECK-NEXT: store ptr [[GEP]], ptr [[P]], align 8
+; CHECK-NEXT: ret ptr [[GEP]]
+;
+ %l.1 = load ptr, ptr %p, align 8
+ call void @foo(ptr %l.1)
+ %l.2 = load ptr, ptr %p, align 8
+ %gep = getelementptr i8, ptr %l.2, i64 4
+ store ptr %gep, ptr %p, align 8
+ %l.3 = load ptr, ptr %p, align 8, !align !0
+ ret ptr %l.3
+}
+
+define ptr @align_replacement_does_not_have_align_metadata2(ptr noalias %p) {
+; CHECK-LABEL: define ptr @align_replacement_does_not_have_align_metadata2(
+; CHECK-SAME: ptr noalias [[P:%.*]]) {
+; CHECK-NEXT: [[L_1:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[L_1]], i64 4
+; CHECK-NEXT: store ptr [[GEP]], ptr [[P]], align 8
+; CHECK-NEXT: ret ptr [[GEP]]
+;
+ %l.1 = load ptr, ptr %p, align 8
+ %gep = getelementptr i8, ptr %l.1, i64 4
+ store ptr %gep, ptr %p, align 8
+ %l.2 = load ptr, ptr %p, align 8, !align !0
+ ret ptr %l.2
+}
+
+define ptr @align_replacement_has_same_alignment(ptr noalias %p) {
+; CHECK-LABEL: define ptr @align_replacement_has_same_alignment(
+; CHECK-SAME: ptr noalias [[P:%.*]]) {
+; CHECK-NEXT: [[L_1:%.*]] = load ptr, ptr [[P]], align 8, !align [[META0:![0-9]+]]
+; CHECK-NEXT: call void @foo(ptr [[L_1]])
+; CHECK-NEXT: ret ptr [[L_1]]
+;
+ %l.1 = load ptr, ptr %p, align 8, !align !0
+ call void @foo(ptr %l.1)
+ %l.2 = load ptr, ptr %p, align 8, !align !0
+ ret ptr %l.2
+}
+
+define ptr @align_replacement_has_smaller_alignment(ptr noalias %p) {
+; CHECK-LABEL: define ptr @align_replacement_has_smaller_alignment(
+; CHECK-SAME: ptr noalias [[P:%.*]]) {
+; CHECK-NEXT: [[L_1:%.*]] = load ptr, ptr [[P]], align 8, !align [[META0]]
+; CHECK-NEXT: call void @foo(ptr [[L_1]])
+; CHECK-NEXT: ret ptr [[L_1]]
+;
+ %l.1 = load ptr, ptr %p, align 8, !align !0
+ call void @foo(ptr %l.1)
+ %l.2 = load ptr, ptr %p, align 8, !align !1
+ ret ptr %l.2
+}
+
+define ptr @align_replacement_has_larger_alignment(ptr %p) {
+; CHECK-LABEL: define ptr @align_replacement_has_larger_alignment(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[L_1:%.*]] = load ptr, ptr [[P]], align 8, !align [[META1:![0-9]+]]
+; CHECK-NEXT: call void @foo(ptr [[L_1]])
+; CHECK-NEXT: [[L_2:%.*]] = load ptr, ptr [[P]], align 8, !align [[META0]]
+; CHECK-NEXT: ret ptr [[L_2]]
+;
+ %l.1 = load ptr, ptr %p, align 8, !align !1
+ call void @foo(ptr %l.1)
+ %l.2 = load ptr, ptr %p, align 8, !align !0
+ ret ptr %l.2
+}
+
+define ptr @align_1(ptr %p) {
+; CHECK-LABEL: define ptr @align_1(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[L_1:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-NEXT: call void @foo(ptr [[L_1]])
+; CHECK-NEXT: [[L_2:%.*]] = load ptr, ptr [[P]], align 8, !align [[META2:![0-9]+]]
+; CHECK-NEXT: ret ptr [[L_2]]
+;
+ %l.1 = load ptr, ptr %p, align 8
+ call void @foo(ptr %l.1)
+ %l.2 = load ptr, ptr %p, align 8, !align !2
+ ret ptr %l.2
+}
+
+!0 = !{i64 4}
+!1 = !{i64 8}
+!2 = !{i64 1}
+;.
+; CHECK: [[META0]] = !{i64 4}
+; CHECK: [[META1]] = !{i64 8}
+; CHECK: [[META2]] = !{i64 1}
+;.
More information about the llvm-commits
mailing list