[llvm] 001da22 - [SimplifyCFG] Add test for hoisting loads with tbaa metadata.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 29 02:39:24 PDT 2024


Author: Florian Hahn
Date: 2024-06-29T10:39:02+01:00
New Revision: 001da2214c2967291cc64ccdac6947b0c2ec77eb

URL: https://github.com/llvm/llvm-project/commit/001da2214c2967291cc64ccdac6947b0c2ec77eb
DIFF: https://github.com/llvm/llvm-project/commit/001da2214c2967291cc64ccdac6947b0c2ec77eb.diff

LOG: [SimplifyCFG] Add test for hoisting loads with tbaa metadata.

Added: 
    llvm/test/Transforms/SimplifyCFG/hoisting-metadata.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/SimplifyCFG/hoisting-metadata.ll b/llvm/test/Transforms/SimplifyCFG/hoisting-metadata.ll
new file mode 100644
index 0000000000000..026002a4942af
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/hoisting-metadata.ll
@@ -0,0 +1,137 @@
+; RUN: opt -p simplifycfg -S %s | FileCheck %s
+
+declare void @init(ptr)
+
+define i64 @hoist_load_with_matching_pointers_and_tbaa(i1 %c) {
+; CHECK-LABEL: define i64 @hoist_load_with_matching_pointers_and_tbaa(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP:%.*]] = alloca i64, align 8
+; CHECK-NEXT:    call void @init(ptr [[TMP]])
+; CHECK-NEXT:    [[TMP0:%.*]] = load i64, ptr [[TMP]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[TMP]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[P:%.*]] = select i1 [[C]], i64 [[TMP0]], i64 [[TMP1]]
+; CHECK-NEXT:    ret i64 [[P]]
+;
+entry:
+  %tmp = alloca i64, align 8
+  call void @init(ptr %tmp)
+  br i1 %c, label %then, label %else
+
+then:
+  %0 = load i64, ptr %tmp, align 8, !tbaa !0
+  br label %exit
+
+else:
+  %1 = load i64, ptr %tmp, align 8, !tbaa !0
+  br label %exit
+
+exit:
+  %p = phi i64 [ %0, %then ], [ %1, %else ]
+  ret i64 %p
+}
+
+define i64 @hoist_load_with_matching_tbaa_
diff erent_pointers(i1 %c) {
+; CHECK-LABEL: define i64 @hoist_load_with_matching_tbaa_
diff erent_pointers(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP:%.*]] = alloca i64, align 8
+; CHECK-NEXT:    [[TMP_1:%.*]] = alloca i64, align 8
+; CHECK-NEXT:    call void @init(ptr [[TMP]])
+; CHECK-NEXT:    call void @init(ptr [[TMP_1]])
+; CHECK-NEXT:    [[TMP0:%.*]] = load i64, ptr [[TMP]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[TMP_1]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[P:%.*]] = select i1 [[C]], i64 [[TMP0]], i64 [[TMP1]]
+; CHECK-NEXT:    ret i64 [[P]]
+;
+entry:
+  %tmp = alloca i64, align 8
+  %tmp.1 = alloca i64, align 8
+  call void @init(ptr %tmp)
+  call void @init(ptr %tmp.1)
+  br i1 %c, label %then, label %else
+
+then:
+  %0 = load i64, ptr %tmp, align 8, !tbaa !0
+  br label %exit
+
+else:
+  %1 = load i64, ptr %tmp.1, align 8, !tbaa !0
+  br label %exit
+
+exit:
+  %p = phi i64 [ %0, %then ], [ %1, %else ]
+  ret i64 %p
+}
+
+define i64 @hoist_load_with_
diff erent_tbaa(i1 %c) {
+; CHECK-LABEL: define i64 @hoist_load_with_
diff erent_tbaa(
+; CHECK-SAME: i1 [[C:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP:%.*]] = alloca i64, align 8
+; CHECK-NEXT:    call void @init(ptr [[TMP]])
+; CHECK-NEXT:    [[TMP0:%.*]] = load i64, ptr [[TMP]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[TMP]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[P:%.*]] = select i1 [[C]], i64 [[TMP0]], i64 [[TMP1]]
+; CHECK-NEXT:    ret i64 [[P]]
+;
+entry:
+  %tmp = alloca i64, align 8
+  call void @init(ptr %tmp)
+  br i1 %c, label %then, label %else
+
+then:
+  %0 = load i64, ptr %tmp, align 8, !tbaa !0
+  br label %exit
+
+else:
+  %1 = load i64, ptr %tmp, align 8, !tbaa !5
+  br label %exit
+
+exit:
+  %p = phi i64 [ %0, %then ], [ %1, %else ]
+  ret i64 %p
+}
+
+define i64 @hoist_
diff erent_ops(i1 %c, i64 %a) {
+; CHECK-LABEL: define i64 @hoist_
diff erent_ops(
+; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]]) {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP:%.*]] = alloca i64, align 8
+; CHECK-NEXT:    call void @init(ptr [[TMP]])
+; CHECK-NEXT:    [[TMP0:%.*]] = load i64, ptr [[TMP]], align 8
+; CHECK-NOT:       !tbaa
+; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[A]], 123
+; CHECK-NEXT:    [[P:%.*]] = select i1 [[C]], i64 [[TMP0]], i64 [[TMP1]]
+; CHECK-NEXT:    ret i64 [[P]]
+;
+entry:
+  %tmp = alloca i64, align 8
+  call void @init(ptr %tmp)
+  br i1 %c, label %then, label %else
+
+then:
+  %0 = load i64, ptr %tmp, align 8, !tbaa !0
+  br label %exit
+
+else:
+  %1 = add i64 %a, 123
+  br label %exit
+
+exit:
+  %p = phi i64 [ %0, %then ], [ %1, %else ]
+  ret i64 %p
+}
+
+!0 = !{!1, !1, i64 0}
+!1 = !{!"p2 long long", !2, i64 0}
+!2 = !{!"any pointer", !3, i64 0}
+!3 = !{!"omnipotent char", !4, i64 0}
+!4 = !{!"Simple C++ TBAA"}
+!5 = !{!3, !3, i64 0}


        


More information about the llvm-commits mailing list