[PATCH] D124178: [ArgPromotion] Change the condition to check the promotion limit

Pavel Samolysov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 07:51:25 PDT 2022


psamolysov created this revision.
psamolysov added reviewers: nikic, aeubanks, kazu, jdoerfert.
psamolysov added a project: LLVM.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
psamolysov requested review of this revision.
Herald added a subscriber: llvm-commits.

The condition should be 'ArgParts.size() > MaxElements', so that if we
have exactly 3 elements in the 'ArgParts' vector, the promotion should
be allowed because the 'MaxElement' threshold is not exceeded yet.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124178

Files:
  llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
  llvm/test/Transforms/ArgumentPromotion/max-elements-limit.ll


Index: llvm/test/Transforms/ArgumentPromotion/max-elements-limit.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/ArgumentPromotion/max-elements-limit.ll
@@ -0,0 +1,56 @@
+; RUN: opt -passes=argpromotion -S -o - %s | FileCheck %s
+
+define internal i32 @callee(i32* noundef %0) {
+; CHECK-LABEL: define {{[^@]+}}@callee
+; CHECK-SAME: (i32 [[P_0:%.*]], i32 [[P_1:%.*]], i32 [[P_2:%.*]]) {
+; CHECK-NEXT:    [[SUM_1:%.*]] = add nsw i32 [[P_0]], [[P_1]]
+; CHECK-NEXT:    [[SUM_2:%.*]] = add nsw i32 [[SUM_1]], [[P_2]]
+; CHECK-NEXT:    ret i32 [[SUM_2]]
+;
+  %2 = getelementptr inbounds i32, i32* %0, i64 0
+  %3 = load i32, i32* %2, align 4
+  %4 = getelementptr inbounds i32, i32* %0, i64 1
+  %5 = load i32, i32* %4, align 4
+  %6 = add nsw i32 %3, %5
+  %7 = getelementptr inbounds i32, i32* %0, i64 2
+  %8 = load i32, i32* %7, align 4
+  %9 = add nsw i32 %6, %8
+  ret i32 %9
+}
+
+define dso_local i32 @caller(i32 %0, i32 %1, i32 %2) {
+; CHECK-LABEL: define {{[^@]+}}@caller
+; CHECK-SAME: (i32 [[P_0:%.*]], i32 [[P_1:%.*]], i32 [[P_2:%.*]]) {
+; CHECK-NEXT:    [[TMP1:%.*]] = alloca [3 x i32], align 4
+; CHECK-NEXT:    [[PL_0:%.*]] = getelementptr inbounds [3 x i32], [3 x i32]* [[TMP1]], i64 0, i64 0
+; CHECK-NEXT:    store i32 [[P_0]], i32* [[PL_0]], align 4
+; CHECK-NEXT:    [[PL_1:%.*]] = getelementptr inbounds i32, i32* [[PL_0]], i64 1
+; CHECK-NEXT:    store i32 [[P_1]], i32* [[PL_1]], align 4
+; CHECK-NEXT:    [[PL_2:%.*]] = getelementptr inbounds i32, i32* [[PL_1]], i64 1
+; CHECK-NEXT:    store i32 [[P_2]], i32* [[PL_2]], align 4
+; CHECK-NEXT:    [[PL_3:%.*]] = getelementptr inbounds [3 x i32], [3 x i32]* [[TMP1]], i64 0, i64 0
+; CHECK-NEXT:    [[VAL_0:%.*]] = load i32, i32* [[PL_3]], align 4
+; CHECK-NEXT:    [[PL_4:%.*]] = getelementptr i32, i32* [[PL_3]], i64 1
+; CHECK-NEXT:    [[VAL_1:%.*]] = load i32, i32* [[PL_4]], align 4
+; CHECK-NEXT:    [[PL_5:%.*]] = getelementptr i32, i32* [[PL_3]], i64 2
+; CHECK-NEXT:    [[VAL_2:%.*]] = load i32, i32* [[PL_5]], align 4
+; CHECK-NEXT:    [[RES:%.*]] = call i32 @callee(i32 [[VAL_0]], i32 [[VAL_1]], i32 [[VAL_2]])
+; CHECK-NEXT:    ret i32 [[RES]]
+;
+  %4 = alloca [3 x i32], align 4
+  %5 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
+  store i32 %0, i32* %5, align 4
+  %6 = getelementptr inbounds i32, i32* %5, i64 1
+  store i32 %1, i32* %6, align 4
+  %7 = getelementptr inbounds i32, i32* %6, i64 1
+  store i32 %2, i32* %7, align 4
+  %8 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
+  %9 = call i32 @callee(i32* noundef %8)
+  ret i32 %9
+}
+
+!llvm.module.flags = !{!0, !1, !2}
+
+!0 = !{i32 1, !"wchar_size", i32 2}
+!1 = !{i32 7, !"PIC Level", i32 2}
+!2 = !{i32 7, !"uwtable", i32 1}
Index: llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
===================================================================
--- llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -513,7 +513,7 @@
 
     // We limit promotion to only promoting up to a fixed number of elements of
     // the aggregate.
-    if (MaxElements > 0 && ArgParts.size() >= MaxElements) {
+    if (MaxElements > 0 && ArgParts.size() > MaxElements) {
       LLVM_DEBUG(dbgs() << "ArgPromotion of " << *Arg << " failed: "
                         << "more than " << MaxElements << " parts\n");
       return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124178.424203.patch
Type: text/x-patch
Size: 3413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220421/97f1338a/attachment.bin>


More information about the llvm-commits mailing list