Skip to content

Commit 5b40a05

Browse files
authored
[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: #103302
1 parent 51bad73 commit 5b40a05

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ bool InstCombinerImpl::foldIntegerTypedPHI(PHINode &PN) {
143143
BasicBlock *BB = std::get<0>(Incoming);
144144
Value *Arg = std::get<1>(Incoming);
145145

146+
// Arg could be a constant, constant expr, etc., which we don't cover here.
147+
if (!isa<Instruction>(Arg) && !isa<Argument>(Arg))
148+
return false;
149+
146150
// First look backward:
147151
if (auto *PI = dyn_cast<PtrToIntInst>(Arg)) {
148152
AvailablePtrVals.emplace_back(PI->getOperand(0));
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S < %s -passes=instcombine | FileCheck %s
3+
4+
; Verify that instcombine doesn't look at users of Constant in different
5+
; functions for dominates() queries.
6+
7+
define void @f1(i1 %a) {
8+
; CHECK-LABEL: define void @f1(
9+
; CHECK-SAME: i1 [[A:%.*]]) {
10+
; CHECK-NEXT: br label %[[BB1:.*]]
11+
; CHECK: [[BB1]]:
12+
; CHECK-NEXT: br i1 [[A]], label %[[BB3:.*]], label %[[BB2:.*]]
13+
; CHECK: [[BB2]]:
14+
; CHECK-NEXT: br label %[[BB3]]
15+
; CHECK: [[BB3]]:
16+
; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ 0, %[[BB2]] ], [ 1, %[[BB1]] ]
17+
; CHECK-NEXT: [[INTTOPTR:%.*]] = inttoptr i64 [[PHI]] to ptr
18+
; CHECK-NEXT: store i32 0, ptr [[INTTOPTR]], align 4
19+
; CHECK-NEXT: br label %[[BB1]]
20+
;
21+
br label %bb1
22+
23+
bb1:
24+
br i1 %a, label %bb3, label %bb2
25+
26+
bb2:
27+
br label %bb3
28+
29+
bb3:
30+
%phi = phi i64 [ 0, %bb2 ], [ 1, %bb1 ]
31+
%inttoptr = inttoptr i64 %phi to ptr
32+
store i32 0, ptr %inttoptr, align 4
33+
br label %bb1
34+
}
35+
36+
define void @f2() {
37+
; CHECK-LABEL: define void @f2() {
38+
; CHECK-NEXT: [[BB:.*:]]
39+
; CHECK-NEXT: ret void
40+
;
41+
bb:
42+
%inttoptr = inttoptr i64 0 to ptr
43+
ret void
44+
}

0 commit comments

Comments
 (0)