[llvm] b1339ab - [InstCombine] Add tests for folding align assumes into load metadata.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 03:52:38 PDT 2024
Author: Florian Hahn
Date: 2024-09-17T11:52:22+01:00
New Revision: b1339abb713063363e7804124b8fb3d84143a003
URL: https://github.com/llvm/llvm-project/commit/b1339abb713063363e7804124b8fb3d84143a003
DIFF: https://github.com/llvm/llvm-project/commit/b1339abb713063363e7804124b8fb3d84143a003.diff
LOG: [InstCombine] Add tests for folding align assumes into load metadata.
Added:
Modified:
llvm/test/Transforms/InstCombine/assume-align.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/assume-align.ll b/llvm/test/Transforms/InstCombine/assume-align.ll
index ce3195d50be7ca..2b8ca5d25fd1a8 100644
--- a/llvm/test/Transforms/InstCombine/assume-align.ll
+++ b/llvm/test/Transforms/InstCombine/assume-align.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals smart
; RUN: opt -S -passes=instcombine,simplifycfg < %s 2>&1 | FileCheck %s
declare void @llvm.assume(i1 noundef)
@@ -122,3 +122,52 @@ define i8 @assume_align_non_pow2(ptr %p) {
%v = load i8, ptr %p
ret i8 %v
}
+
+; TODO: Can fold alignment assumption into !align metadata on load.
+define ptr @fold_assume_align_pow2_of_loaded_pointer_into_align_metadata(ptr %p) {
+; CHECK-LABEL: @fold_assume_align_pow2_of_loaded_pointer_into_align_metadata(
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P:%.*]], align 8
+; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P2]], i64 8) ]
+; CHECK-NEXT: ret ptr [[P2]]
+;
+ %p2 = load ptr, ptr %p
+ call void @llvm.assume(i1 true) [ "align"(ptr %p2, i64 8) ]
+ ret ptr %p2
+}
+
+define ptr @dont_fold_assume_align_pow2_of_loaded_pointer_into_align_metadata_due_to_call(ptr %p) {
+; CHECK-LABEL: @dont_fold_assume_align_pow2_of_loaded_pointer_into_align_metadata_due_to_call(
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P:%.*]], align 8
+; CHECK-NEXT: call void @g(i64 0)
+; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P2]], i64 8) ]
+; CHECK-NEXT: ret ptr [[P2]]
+;
+ %p2 = load ptr, ptr %p
+ call void @g(i64 0)
+ call void @llvm.assume(i1 true) [ "align"(ptr %p2, i64 8) ]
+ ret ptr %p2
+}
+
+; !align must have a power-of-2 alignment.
+define ptr @dont_fold_assume_align_non_pow2_of_loaded_pointer_into_align_metadata(ptr %p) {
+; CHECK-LABEL: @dont_fold_assume_align_non_pow2_of_loaded_pointer_into_align_metadata(
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P:%.*]], align 8
+; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P2]], i64 13) ]
+; CHECK-NEXT: ret ptr [[P2]]
+;
+ %p2 = load ptr, ptr %p
+ call void @llvm.assume(i1 true) [ "align"(ptr %p2, i64 13) ]
+ ret ptr %p2
+}
+
+; !align must have a power-of-2 alignment.
+define ptr @dont_fold_assume_align_zero_of_loaded_pointer_into_align_metadata(ptr %p) {
+; CHECK-LABEL: @dont_fold_assume_align_zero_of_loaded_pointer_into_align_metadata(
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P:%.*]], align 8
+; CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[P2]], i64 0) ]
+; CHECK-NEXT: ret ptr [[P2]]
+;
+ %p2 = load ptr, ptr %p
+ call void @llvm.assume(i1 true) [ "align"(ptr %p2, i64 0) ]
+ ret ptr %p2
+}
More information about the llvm-commits
mailing list