Skip to content

PHITransAddr: Avoid looking at constant use lists #134689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Apr 7, 2025

Avoids asserts in GVN

Copy link
Contributor Author

arsenm commented Apr 7, 2025

@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2025

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

Avoids asserts in GVN


Full diff: https://github.com/llvm/llvm-project/pull/134689.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/PHITransAddr.cpp (+3)
  • (modified) llvm/test/Transforms/GVN/pr65447.ll (+76-7)
diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp
index e42113db42781..276708c2ebf77 100644
--- a/llvm/lib/Analysis/PHITransAddr.cpp
+++ b/llvm/lib/Analysis/PHITransAddr.cpp
@@ -224,6 +224,9 @@ Value *PHITransAddr::translateSubExpr(Value *V, BasicBlock *CurBB,
 
     // Scan to see if we have this GEP available.
     Value *APHIOp = GEPOps[0];
+    if (isa<ConstantData>(APHIOp))
+      return nullptr;
+
     for (User *U : APHIOp->users()) {
       if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(U))
         if (GEPI->getType() == GEP->getType() &&
diff --git a/llvm/test/Transforms/GVN/pr65447.ll b/llvm/test/Transforms/GVN/pr65447.ll
index 1b951e907e822..1fa3811a3a81d 100644
--- a/llvm/test/Transforms/GVN/pr65447.ll
+++ b/llvm/test/Transforms/GVN/pr65447.ll
@@ -2,29 +2,98 @@
 ; RUN: opt -S -passes=gvn < %s | FileCheck %s
 
 ; Make sure deduplicated phi nodes are removed from the VN map.
-define i64 @f() {
-; CHECK-LABEL: define i64 @f() {
+define i64 @f2(ptr %arg) {
+; CHECK-LABEL: define i64 @f2(
+; CHECK-SAME: ptr [[ARG:%.*]]) {
+; CHECK-NEXT:  BB:
+; CHECK-NEXT:    store i1 false, ptr [[ARG]], align 1
+; CHECK-NEXT:    br label [[BB2D:%.*]]
+; CHECK:       BB2a:
+; CHECK-NEXT:    br label [[BB2B:%.*]]
+; CHECK:       BB2b:
+; CHECK-NEXT:    br label [[BB2C:%.*]]
+; CHECK:       BB2c:
+; CHECK-NEXT:    [[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], [[BB2D]] ]
+; CHECK-NEXT:    [[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64
+; CHECK-NEXT:    [[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[DOTPHI_TRANS_INSERT]]
+; CHECK-NEXT:    [[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], align 1
+; CHECK-NEXT:    br label [[BB2D]]
+; CHECK:       BB2d:
+; CHECK-NEXT:    [[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB:%.*]] ]
+; CHECK-NEXT:    [[L93:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, [[BB]] ]
+; CHECK-NEXT:    [[TMP0:%.*]] = sext i1 [[AZ]] to i64
+; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i1, ptr [[ARG]], i64 [[TMP0]]
+; CHECK-NEXT:    store i1 [[AZ]], ptr [[ARG]], align 2
+; CHECK-NEXT:    br i1 [[L93]], label [[BB2C]], label [[BB1E:%.*]]
+; CHECK:       BB1e:
+; CHECK-NEXT:    br i1 [[AZ]], label [[BB2F:%.*]], label [[BB4:%.*]]
+; CHECK:       BB2f:
+; CHECK-NEXT:    store i1 true, ptr [[ARG]], align 2
+; CHECK-NEXT:    br label [[BB2B]]
+; CHECK:       BB4:
+; CHECK-NEXT:    br label [[BB4]]
+;
+BB:
+  store i1 false, ptr %arg, align 1
+  br label %BB2d
+
+BB2a: ; No predecessors!
+  br label %BB2b
+
+BB2b:       ; preds = %BB2f, %BB2a
+  br label %BB2c
+
+BB2c:                     ; preds = %BB2d, %BB2b
+  %0 = phi i1 [ true, %BB2b ], [ %1, %BB2d ]
+  br label %BB2d
+
+BB2d:                              ; preds = %BB2c, %BB
+  %1 = phi i1 [ %0, %BB2c ], [ false, %BB ]
+  %2 = sext i1 %1 to i64
+  %gep2 = getelementptr i1, ptr %arg, i64 %2
+  %L93 = load i1, ptr %gep2, align 1
+  %Az = load i1, ptr %arg, align 2
+  store i1 %1, ptr %arg, align 2
+  br i1 %L93, label %BB2c, label %BB1e
+
+BB1e:                                        ; preds = %BB2d
+  br i1 %Az, label %BB2f, label %BB4
+
+BB2f:                                ; preds = %BB1e
+  store i1 true, ptr %arg, align 2
+  br label %BB2b
+
+BB4:                                              ; preds = %BB1e, %BB4
+  br label %BB4
+
+; uselistorder directives
+  uselistorder label %BB4, { 1, 0 }
+}
+
+; Make sure deduplicated phi nodes are removed from the VN map. Make
+; sure there is no assert on attempt to use ConstantData use lists.
+define i64 @f_null() {
+; CHECK-LABEL: define i64 @f_null() {
 ; CHECK-NEXT:  BB:
 ; CHECK-NEXT:    store i1 false, ptr null, align 1
 ; CHECK-NEXT:    br label [[BB2D:%.*]]
 ; CHECK:       BB2a:
 ; CHECK-NEXT:    br label [[BB2B:%.*]]
 ; CHECK:       BB2b:
-; CHECK-NEXT:    [[L93_PRE_PRE:%.*]] = load i1, ptr inttoptr (i64 -1 to ptr), align 1
 ; CHECK-NEXT:    br label [[BB2C:%.*]]
 ; CHECK:       BB2c:
-; CHECK-NEXT:    [[L93_PRE:%.*]] = phi i1 [ [[L93_PRE_PRE]], [[BB2B]] ], [ true, [[BB2D]] ]
 ; CHECK-NEXT:    [[AZ2:%.*]] = phi i1 [ true, [[BB2B]] ], [ [[AZ:%.*]], [[BB2D]] ]
 ; CHECK-NEXT:    [[DOTPHI_TRANS_INSERT:%.*]] = sext i1 [[AZ2]] to i64
 ; CHECK-NEXT:    [[GEP2_PHI_TRANS_INSERT:%.*]] = getelementptr i1, ptr null, i64 [[DOTPHI_TRANS_INSERT]]
+; CHECK-NEXT:    [[L93_PRE:%.*]] = load i1, ptr [[GEP2_PHI_TRANS_INSERT]], align 1
 ; CHECK-NEXT:    br label [[BB2D]]
 ; CHECK:       BB2d:
-; CHECK-NEXT:    [[L93_PRE5:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, [[BB:%.*]] ]
-; CHECK-NEXT:    [[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB]] ]
+; CHECK-NEXT:    [[AZ]] = phi i1 [ [[AZ2]], [[BB2C]] ], [ false, [[BB:%.*]] ]
+; CHECK-NEXT:    [[L93:%.*]] = phi i1 [ [[L93_PRE]], [[BB2C]] ], [ false, [[BB]] ]
 ; CHECK-NEXT:    [[TMP0:%.*]] = sext i1 [[AZ]] to i64
 ; CHECK-NEXT:    [[GEP2:%.*]] = getelementptr i1, ptr null, i64 [[TMP0]]
 ; CHECK-NEXT:    store i1 [[AZ]], ptr null, align 2
-; CHECK-NEXT:    br i1 [[L93_PRE5]], label [[BB2C]], label [[BB1E:%.*]]
+; CHECK-NEXT:    br i1 [[L93]], label [[BB2C]], label [[BB1E:%.*]]
 ; CHECK:       BB1e:
 ; CHECK-NEXT:    br i1 [[AZ]], label [[BB2F:%.*]], label [[BB4:%.*]]
 ; CHECK:       BB2f:

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm force-pushed the users/arsenm/instcombine-skip-sincospi-optimization-constantdata branch from fea5554 to c0e8aed Compare April 8, 2025 00:25
@arsenm arsenm force-pushed the users/arsenm/phi-trans-addr-stop-using-constantdata-use-lists branch from a87e23c to d4cc3ae Compare April 8, 2025 00:25
@arsenm arsenm force-pushed the users/arsenm/instcombine-skip-sincospi-optimization-constantdata branch from c0e8aed to e0e5a05 Compare April 12, 2025 09:25
@arsenm arsenm force-pushed the users/arsenm/phi-trans-addr-stop-using-constantdata-use-lists branch from d4cc3ae to 2c9dfd2 Compare April 12, 2025 09:25
@arsenm arsenm force-pushed the users/arsenm/instcombine-skip-sincospi-optimization-constantdata branch from e0e5a05 to a59013c Compare April 13, 2025 10:16
@arsenm arsenm force-pushed the users/arsenm/phi-trans-addr-stop-using-constantdata-use-lists branch from 2c9dfd2 to 744e2c1 Compare April 13, 2025 10:16
arsenm added a commit that referenced this pull request Apr 13, 2025
@arsenm
Copy link
Contributor Author

arsenm commented Apr 13, 2025

b37476f

@arsenm arsenm closed this Apr 13, 2025
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
@arsenm arsenm deleted the users/arsenm/phi-trans-addr-stop-using-constantdata-use-lists branch April 25, 2025 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants