[llvm] 8af8119 - [ArgPromotion] Add test with bitcasts (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 05:46:34 PST 2022


Author: Nikita Popov
Date: 2022-02-02T14:46:27+01:00
New Revision: 8af8119177411286f5c04022e98afe69383d4181

URL: https://github.com/llvm/llvm-project/commit/8af8119177411286f5c04022e98afe69383d4181
DIFF: https://github.com/llvm/llvm-project/commit/8af8119177411286f5c04022e98afe69383d4181.diff

LOG: [ArgPromotion] Add test with bitcasts (NFC)

Argument promotion currently doesn't handle these.

Added: 
    llvm/test/Transforms/ArgumentPromotion/bitcasts.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ArgumentPromotion/bitcasts.ll b/llvm/test/Transforms/ArgumentPromotion/bitcasts.ll
new file mode 100644
index 0000000000000..68a3223cf9972
--- /dev/null
+++ b/llvm/test/Transforms/ArgumentPromotion/bitcasts.ll
@@ -0,0 +1,64 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
+; RUN: opt -S -argpromotion < %s | FileCheck %s
+
+; Test argument promotion involving bitcasts.
+
+%opaque = type opaque
+
+define internal i32 @callee_basic(i8* %p) {
+; CHECK-LABEL: define {{[^@]+}}@callee_basic
+; CHECK-SAME: (i8* [[P:%.*]]) {
+; CHECK-NEXT:    [[P_32:%.*]] = bitcast i8* [[P]] to i32*
+; CHECK-NEXT:    [[X:%.*]] = load i32, i32* [[P_32]], align 4
+; CHECK-NEXT:    [[P1:%.*]] = getelementptr i8, i8* [[P]], i64 4
+; CHECK-NEXT:    [[P1_32:%.*]] = bitcast i8* [[P1]] to i32*
+; CHECK-NEXT:    [[Y:%.*]] = load i32, i32* [[P1_32]], align 4
+; CHECK-NEXT:    [[Z:%.*]] = add i32 [[X]], [[Y]]
+; CHECK-NEXT:    ret i32 [[Z]]
+;
+  %p.32 = bitcast i8* %p to i32*
+  %x = load i32, i32* %p.32
+  %p1 = getelementptr i8, i8* %p, i64 4
+  %p1.32 = bitcast i8* %p1 to i32*
+  %y = load i32, i32* %p1.32
+  %z = add i32 %x, %y
+  ret i32 %z
+}
+
+define void @caller_basic(i8* %p) {
+; CHECK-LABEL: define {{[^@]+}}@caller_basic
+; CHECK-SAME: (i8* [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_basic(i8* [[P]])
+; CHECK-NEXT:    ret void
+;
+  call i32 @callee_basic(i8* %p)
+  ret void
+}
+
+define internal i32 @callee_opaque(%opaque* %p) {
+; CHECK-LABEL: define {{[^@]+}}@callee_opaque
+; CHECK-SAME: (%opaque* [[P:%.*]]) {
+; CHECK-NEXT:    [[P_32:%.*]] = bitcast %opaque* [[P]] to i32*
+; CHECK-NEXT:    [[X:%.*]] = load i32, i32* [[P_32]], align 4
+; CHECK-NEXT:    [[P1_32:%.*]] = getelementptr i32, i32* [[P_32]], i64 1
+; CHECK-NEXT:    [[Y:%.*]] = load i32, i32* [[P1_32]], align 4
+; CHECK-NEXT:    [[Z:%.*]] = add i32 [[X]], [[Y]]
+; CHECK-NEXT:    ret i32 [[Z]]
+;
+  %p.32 = bitcast %opaque* %p to i32*
+  %x = load i32, i32* %p.32
+  %p1.32 = getelementptr i32, i32* %p.32, i64 1
+  %y = load i32, i32* %p1.32
+  %z = add i32 %x, %y
+  ret i32 %z
+}
+
+define void @caller_opaque(%opaque* %p) {
+; CHECK-LABEL: define {{[^@]+}}@caller_opaque
+; CHECK-SAME: (%opaque* [[P:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_opaque(%opaque* [[P]])
+; CHECK-NEXT:    ret void
+;
+  call i32 @callee_opaque(%opaque* %p)
+  ret void
+}


        


More information about the llvm-commits mailing list