Skip to content

Commit 9d16660

Browse files
committed
!fixup check add has one use.
1 parent c012a9c commit 9d16660

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,7 +2077,8 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {
20772077
Value *Base;
20782078
Value *Offset;
20792079
if (match(CI.getOperand(0),
2080-
m_c_Add(m_PtrToIntSameSize(DL, m_Value(Base)), m_Value(Offset))) &&
2080+
m_OneUse(m_c_Add(m_PtrToIntSameSize(DL, m_Value(Base)),
2081+
m_Value(Offset)))) &&
20812082
CI.getType()->getPointerAddressSpace() ==
20822083
Base->getType()->getPointerAddressSpace() &&
20832084
all_of(CI.users(), IsaPred<ICmpInst>)) {

llvm/test/Transforms/InstCombine/fold-bin-operand.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ define i1 @inttoptr_add_ptrtoint_used_by_single_icmp_int_type_does_not_match_ptr
129129
ret i1 %c
130130
}
131131

132+
define i1 @inttoptr_add_multiple_users_ptrtoint_used_by_single_icmp(ptr %src, ptr %p2) {
133+
; CHECK-LABEL: @inttoptr_add_multiple_users_ptrtoint_used_by_single_icmp(
134+
; CHECK-NEXT: [[I:%.*]] = ptrtoint ptr [[SRC:%.*]] to i64
135+
; CHECK-NEXT: [[A:%.*]] = add i64 [[I]], 10
136+
; CHECK-NEXT: [[P:%.*]] = inttoptr i64 [[A]] to ptr
137+
; CHECK-NEXT: [[C:%.*]] = icmp eq ptr [[P2:%.*]], [[P]]
138+
; CHECK-NEXT: call void @bar(i64 [[A]])
139+
; CHECK-NEXT: ret i1 [[C]]
140+
;
141+
%i = ptrtoint ptr %src to i64
142+
%a = add i64 %i, 10
143+
%p = inttoptr i64 %a to ptr
144+
%c = icmp eq ptr %p, %p2
145+
call void @bar(i64 %a)
146+
ret i1 %c
147+
}
148+
132149
define i1 @multiple_inttoptr_add_ptrtoint_used_by_single_icmp(ptr %src) {
133150
; CHECK-LABEL: @multiple_inttoptr_add_ptrtoint_used_by_single_icmp(
134151
; CHECK-NEXT: ret i1 false
@@ -210,6 +227,7 @@ define i1 @inttoptr_add_ptrtoint_used_by_multiple_icmps(ptr %src, ptr %p2, ptr %
210227
}
211228

212229
declare void @foo(ptr)
230+
declare void @bar(i64)
213231

214232
define i1 @inttoptr_add_ptrtoint_used_by_multiple_icmps_and_other_user(ptr %src, ptr %p2, ptr %p3) {
215233
; CHECK-LABEL: @inttoptr_add_ptrtoint_used_by_multiple_icmps_and_other_user(

0 commit comments

Comments
 (0)