[llvm] b896334 - [ArgPromotion] Check dereferenceability on argument as well
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 8 01:31:58 PST 2022
Author: Nikita Popov
Date: 2022-02-08T10:29:51+01:00
New Revision: b896334834305c8b68b9b6e6cb4386adb4ed1a07
URL: https://github.com/llvm/llvm-project/commit/b896334834305c8b68b9b6e6cb4386adb4ed1a07
DIFF: https://github.com/llvm/llvm-project/commit/b896334834305c8b68b9b6e6cb4386adb4ed1a07.diff
LOG: [ArgPromotion] Check dereferenceability on argument as well
Before walking all the callers, check whether we have a
dereferenceable attribute directly on the argument.
Also make it clearer that the code currently does not treat
alignment correctly.
Added:
Modified:
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
llvm/test/Transforms/ArgumentPromotion/align.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index e6a542385662f..d1d880c4d0682 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -477,18 +477,20 @@ doPromotion(Function *F, SmallPtrSetImpl<Argument *> &ArgsToPromote,
static bool allCallersPassValidPointerForArgument(Argument *Arg, Type *Ty) {
Function *Callee = Arg->getParent();
const DataLayout &DL = Callee->getParent()->getDataLayout();
+ Align NeededAlign(1); // TODO: This is incorrect!
+ APInt Bytes(64, DL.getTypeStoreSize(Ty));
- unsigned ArgNo = Arg->getArgNo();
+ // Check if the argument itself is marked dereferenceable and aligned.
+ if (isDereferenceableAndAlignedPointer(Arg, NeededAlign, Bytes, DL))
+ return true;
// Look at all call sites of the function. At this point we know we only have
// direct callees.
- for (User *U : Callee->users()) {
+ return all_of(Callee->users(), [&](User *U) {
CallBase &CB = cast<CallBase>(*U);
-
- if (!isDereferenceablePointer(CB.getArgOperand(ArgNo), Ty, DL))
- return false;
- }
- return true;
+ return isDereferenceableAndAlignedPointer(
+ CB.getArgOperand(Arg->getArgNo()), NeededAlign, Bytes, DL);
+ });
}
/// Returns true if Prefix is a prefix of longer. That means, Longer has a size
diff --git a/llvm/test/Transforms/ArgumentPromotion/align.ll b/llvm/test/Transforms/ArgumentPromotion/align.ll
index 45c9d64865684..7e30e8b50a482 100644
--- a/llvm/test/Transforms/ArgumentPromotion/align.ll
+++ b/llvm/test/Transforms/ArgumentPromotion/align.ll
@@ -53,11 +53,10 @@ define void @caller_guaranteed_aligned_1(i1 %c, i32* align 16 dereferenceable(4)
define internal i32 @callee_guaranteed_aligned_2(i1 %c, i32* align 16 dereferenceable(4) %p) {
; CHECK-LABEL: define {{[^@]+}}@callee_guaranteed_aligned_2
-; CHECK-SAME: (i1 [[C:%.*]], i32* align 16 dereferenceable(4) [[P:%.*]]) {
+; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_VAL:%.*]]) {
; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
; CHECK: if:
-; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[P]], align 16
-; CHECK-NEXT: ret i32 [[X]]
+; CHECK-NEXT: ret i32 [[P_VAL]]
; CHECK: else:
; CHECK-NEXT: ret i32 -1
;
@@ -74,7 +73,8 @@ else:
define void @caller_guaranteed_aligned_2(i1 %c, i32* %p) {
; CHECK-LABEL: define {{[^@]+}}@caller_guaranteed_aligned_2
; CHECK-SAME: (i1 [[C:%.*]], i32* [[P:%.*]]) {
-; CHECK-NEXT: [[TMP1:%.*]] = call i32 @callee_guaranteed_aligned_2(i1 [[C]], i32* [[P]])
+; CHECK-NEXT: [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @callee_guaranteed_aligned_2(i1 [[C]], i32 [[P_VAL]])
; CHECK-NEXT: ret void
;
call i32 @callee_guaranteed_aligned_2(i1 %c, i32* %p)
More information about the llvm-commits
mailing list