Skip to content

Commit 7900e63

Browse files
committed
[InstCombine] Support ptrtoaddr when converting to align assume bundle
ptrtoaddr can be treated the same way as ptrtoint here.
1 parent 21ab523 commit 7900e63

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3496,7 +3496,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
34963496
if (isPowerOf2_64(AlignMask + 1)) {
34973497
uint64_t Offset = 0;
34983498
match(A, m_Add(m_Value(A), m_ConstantInt(Offset)));
3499-
if (match(A, m_PtrToInt(m_Value(A)))) {
3499+
if (match(A, m_PtrToIntOrAddr(m_Value(A)))) {
35003500
/// Note: this doesn't preserve the offset information but merges
35013501
/// offset and alignment.
35023502
/// TODO: we can generate a GEP instead of merging the alignment with

llvm/test/Transforms/InstCombine/assume.ll

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ declare void @llvm.assume(i1) #1
1010

1111
; Check that the assume has not been removed:
1212

13-
define i32 @foo1(ptr %a) #0 {
14-
; DEFAULT-LABEL: @foo1(
13+
define i32 @align_to_bundle(ptr %a) #0 {
14+
; DEFAULT-LABEL: @align_to_bundle(
1515
; DEFAULT-NEXT: [[T0:%.*]] = load i32, ptr [[A:%.*]], align 4
1616
; DEFAULT-NEXT: [[PTRINT:%.*]] = ptrtoint ptr [[A]] to i64
1717
; DEFAULT-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 31
1818
; DEFAULT-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
1919
; DEFAULT-NEXT: tail call void @llvm.assume(i1 [[MASKCOND]])
2020
; DEFAULT-NEXT: ret i32 [[T0]]
2121
;
22-
; BUNDLES-LABEL: @foo1(
22+
; BUNDLES-LABEL: @align_to_bundle(
2323
; BUNDLES-NEXT: [[T0:%.*]] = load i32, ptr [[A:%.*]], align 4
2424
; BUNDLES-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i64 32) ]
2525
; BUNDLES-NEXT: ret i32 [[T0]]
@@ -32,6 +32,28 @@ define i32 @foo1(ptr %a) #0 {
3232
ret i32 %t0
3333
}
3434

35+
define i32 @align_to_bundle_ptrtoaddr(ptr %a) #0 {
36+
; DEFAULT-LABEL: @align_to_bundle_ptrtoaddr(
37+
; DEFAULT-NEXT: [[T0:%.*]] = load i32, ptr [[A:%.*]], align 4
38+
; DEFAULT-NEXT: [[PTRINT:%.*]] = ptrtoaddr ptr [[A]] to i64
39+
; DEFAULT-NEXT: [[MASKEDPTR:%.*]] = and i64 [[PTRINT]], 31
40+
; DEFAULT-NEXT: [[MASKCOND:%.*]] = icmp eq i64 [[MASKEDPTR]], 0
41+
; DEFAULT-NEXT: tail call void @llvm.assume(i1 [[MASKCOND]])
42+
; DEFAULT-NEXT: ret i32 [[T0]]
43+
;
44+
; BUNDLES-LABEL: @align_to_bundle_ptrtoaddr(
45+
; BUNDLES-NEXT: [[T0:%.*]] = load i32, ptr [[A:%.*]], align 4
46+
; BUNDLES-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr [[A]], i64 32) ]
47+
; BUNDLES-NEXT: ret i32 [[T0]]
48+
;
49+
%t0 = load i32, ptr %a, align 4
50+
%ptrint = ptrtoaddr ptr %a to i64
51+
%maskedptr = and i64 %ptrint, 31
52+
%maskcond = icmp eq i64 %maskedptr, 0
53+
tail call void @llvm.assume(i1 %maskcond)
54+
ret i32 %t0
55+
}
56+
3557
define i32 @align_assume_trunc_cond(ptr %a) #0 {
3658
; DEFAULT-LABEL: @align_assume_trunc_cond(
3759
; DEFAULT-NEXT: [[T0:%.*]] = load i32, ptr [[A:%.*]], align 4

0 commit comments

Comments
 (0)