[llvm] 5b40a05 - [InstCombine] Don't look at ConstantData users

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 11:44:48 PDT 2024


Author: Alexis Engelke
Date: 2024-08-13T20:44:45+02:00
New Revision: 5b40a05d8f2872e4822fd5ff18383fbd5944f511

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

LOG: [InstCombine] Don't look at ConstantData users

When looking at PHI operand for combining, only look at instructions and
arguments. The loop later iteraters over Arg's users, which is not
useful if Arg is a constant -- it's users are not meaningful and might
be in different functions, which causes problems for the dominates()
query.

Pull Request: https://github.com/llvm/llvm-project/pull/103302

Added: 
    llvm/test/Transforms/InstCombine/phi-int-users.ll

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 86411320ab2487..bcff9a72b65724 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -143,6 +143,10 @@ bool InstCombinerImpl::foldIntegerTypedPHI(PHINode &PN) {
     BasicBlock *BB = std::get<0>(Incoming);
     Value *Arg = std::get<1>(Incoming);
 
+    // Arg could be a constant, constant expr, etc., which we don't cover here.
+    if (!isa<Instruction>(Arg) && !isa<Argument>(Arg))
+      return false;
+
     // First look backward:
     if (auto *PI = dyn_cast<PtrToIntInst>(Arg)) {
       AvailablePtrVals.emplace_back(PI->getOperand(0));

diff  --git a/llvm/test/Transforms/InstCombine/phi-int-users.ll b/llvm/test/Transforms/InstCombine/phi-int-users.ll
new file mode 100644
index 00000000000000..6c98cc8a1c900c
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/phi-int-users.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S < %s -passes=instcombine | FileCheck %s
+
+; Verify that instcombine doesn't look at users of Constant in 
diff erent
+; functions for dominates() queries.
+
+define void @f1(i1 %a) {
+; CHECK-LABEL: define void @f1(
+; CHECK-SAME: i1 [[A:%.*]]) {
+; CHECK-NEXT:    br label %[[BB1:.*]]
+; CHECK:       [[BB1]]:
+; CHECK-NEXT:    br i1 [[A]], label %[[BB3:.*]], label %[[BB2:.*]]
+; CHECK:       [[BB2]]:
+; CHECK-NEXT:    br label %[[BB3]]
+; CHECK:       [[BB3]]:
+; CHECK-NEXT:    [[PHI:%.*]] = phi i64 [ 0, %[[BB2]] ], [ 1, %[[BB1]] ]
+; CHECK-NEXT:    [[INTTOPTR:%.*]] = inttoptr i64 [[PHI]] to ptr
+; CHECK-NEXT:    store i32 0, ptr [[INTTOPTR]], align 4
+; CHECK-NEXT:    br label %[[BB1]]
+;
+  br label %bb1
+
+bb1:
+  br i1 %a, label %bb3, label %bb2
+
+bb2:
+  br label %bb3
+
+bb3:
+  %phi = phi i64 [ 0, %bb2 ], [ 1, %bb1 ]
+  %inttoptr = inttoptr i64 %phi to ptr
+  store i32 0, ptr %inttoptr, align 4
+  br label %bb1
+}
+
+define void @f2() {
+; CHECK-LABEL: define void @f2() {
+; CHECK-NEXT:  [[BB:.*:]]
+; CHECK-NEXT:    ret void
+;
+bb:
+  %inttoptr = inttoptr i64 0 to ptr
+  ret void
+}


        


More information about the llvm-commits mailing list