[llvm] a24cc48 - [ArgPromotion] Add alignment test (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 01:45:21 PST 2022


Author: Nikita Popov
Date: 2022-02-01T10:45:14+01:00
New Revision: a24cc48bc6ff9abb09c73f8d9a3c32c154e48968

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

LOG: [ArgPromotion] Add alignment test (NFC)

This shows a miscompile in the current argpromotion implementation:
We may speculatively execute overaligned loads.

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

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ArgumentPromotion/align.ll b/llvm/test/Transforms/ArgumentPromotion/align.ll
new file mode 100644
index 000000000000..5d8ceee28529
--- /dev/null
+++ b/llvm/test/Transforms/ArgumentPromotion/align.ll
@@ -0,0 +1,84 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
+; RUN: opt -S -argpromotion < %s | FileCheck %s
+
+define internal i32 @callee_must_exec(i32* %p) {
+; CHECK-LABEL: define {{[^@]+}}@callee_must_exec
+; CHECK-SAME: (i32 [[P_VAL:%.*]]) {
+; CHECK-NEXT:    ret i32 [[P_VAL]]
+;
+  %x = load i32, i32* %p, align 16
+  ret i32 %x
+}
+
+define void @caller_must_exec(i32* %p) {
+; CHECK-LABEL: define {{[^@]+}}@caller_must_exec
+; CHECK-SAME: (i32* [[P:%.*]]) {
+; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_must_exec(i32 [[P_VAL]])
+; CHECK-NEXT:    ret void
+;
+  call i32 @callee_must_exec(i32* %p)
+  ret void
+}
+
+define internal i32 @callee_guaranteed_aligned(i1 %c, i32* %p) {
+; CHECK-LABEL: define {{[^@]+}}@callee_guaranteed_aligned
+; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_VAL:%.*]]) {
+; CHECK-NEXT:    br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK:       if:
+; CHECK-NEXT:    ret i32 [[P_VAL]]
+; CHECK:       else:
+; CHECK-NEXT:    ret i32 -1
+;
+  br i1 %c, label %if, label %else
+
+if:
+  %x = load i32, i32* %p, align 16
+  ret i32 %x
+
+else:
+  ret i32 -1
+}
+
+define void @caller_guaranteed_aligned(i1 %c, i32* align 16 dereferenceable(4) %p) {
+; CHECK-LABEL: define {{[^@]+}}@caller_guaranteed_aligned
+; CHECK-SAME: (i1 [[C:%.*]], i32* align 16 dereferenceable(4) [[P:%.*]]) {
+; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_guaranteed_aligned(i1 [[C]], i32 [[P_VAL]])
+; CHECK-NEXT:    ret void
+;
+  call i32 @callee_guaranteed_aligned(i1 %c, i32* %p)
+  ret void
+}
+
+; TODO: This should not be promoted, as the caller only guarantees that the
+; pointer is dereferenceable, not that it is aligned.
+define internal i32 @callee_not_guaranteed_aligned(i1 %c, i32* %p) {
+; CHECK-LABEL: define {{[^@]+}}@callee_not_guaranteed_aligned
+; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_VAL:%.*]]) {
+; CHECK-NEXT:    br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK:       if:
+; CHECK-NEXT:    ret i32 [[P_VAL]]
+; CHECK:       else:
+; CHECK-NEXT:    ret i32 -1
+;
+  br i1 %c, label %if, label %else
+
+if:
+  %x = load i32, i32* %p, align 16
+  ret i32 %x
+
+else:
+  ret i32 -1
+}
+
+define void @caller_not_guaranteed_aligned(i1 %c, i32* dereferenceable(4) %p) {
+; CHECK-LABEL: define {{[^@]+}}@caller_not_guaranteed_aligned
+; CHECK-SAME: (i1 [[C:%.*]], i32* dereferenceable(4) [[P:%.*]]) {
+; CHECK-NEXT:    [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
+; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @callee_not_guaranteed_aligned(i1 [[C]], i32 [[P_VAL]])
+; CHECK-NEXT:    ret void
+;
+  call i32 @callee_not_guaranteed_aligned(i1 %c, i32* %p)
+  ret void
+}


        


More information about the llvm-commits mailing list