xref: /llvm-project/llvm/test/Analysis/ValueTracking/knownzero-addrspacecast.ll (revision 7fbbbfd63899331a47a0265c45f1a2a2ae6918d4)
1; RUN: opt -passes=instcombine -S < %s | FileCheck %s
2
3; When a pointer is addrspacecasted to a another addr space, we cannot assume
4; anything about the new bits.
5
6target datalayout = "p:32:32-p3:32:32-p4:64:64"
7
8; CHECK-LABEL: @test_shift
9; CHECK-NOT: ret i64 0
10define i64 @test_shift(ptr %p) {
11  %g = addrspacecast ptr %p to ptr addrspace(4)
12  %i = ptrtoint ptr addrspace(4) %g to i64
13  %shift = lshr i64 %i, 32
14  ret i64 %shift
15}
16
17; CHECK-LABEL: @test_null
18; A null pointer casted to another addr space may no longer have null value.
19; CHECK-NOT: ret i32 0
20define i32 @test_null() {
21  %g = addrspacecast ptr null to ptr addrspace(3)
22  %i = ptrtoint ptr addrspace(3) %g to i32
23  ret i32 %i
24}
25