Skip to content

[InstCombine] Don't look at ConstantData users #103302

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
44 changes: 44 additions & 0 deletions llvm/test/Transforms/InstCombine/phi-int-users.ll
Copy link
Contributor

Choose a reason for hiding this comment

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

This test still doesn't look anything approaching minimal. Please run it through llvm-reduce.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Fun fact, llvm-reduce crashed on the input due to this bug.

Original file line number Diff line number Diff line change
@@ -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 different
; 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
}
Loading