forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix known zero bits for addrspacecast.
Currently LLVM assumes that a pointer addrspacecasted to a different addr space is equivalent to trunc or zext bitwise, which is not true. For example, in amdgcn target, when a null pointer is addrspacecasted from addr space 4 to 0, its value is changed from i64 0 to i32 -1. This patch teaches LLVM not to assume known bits of addrspacecast instruction to its operand. Differential Revision: https://reviews.llvm.org/D26803 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287545 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
3 changed files
with
24 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
; RUN: opt -instcombine -S < %s | FileCheck %s | ||
|
||
; When a pointer is addrspacecasted to a another addr space, we cannot assume | ||
; anything about the new bits. | ||
|
||
target datalayout = "p:32:32-p3:32:32-p4:64:64" | ||
|
||
; CHECK-LABEL: @test_shift | ||
; CHECK-NOT: ret i64 0 | ||
define i64 @test_shift(i8* %p) { | ||
%g = addrspacecast i8* %p to i8 addrspace(4)* | ||
%i = ptrtoint i8 addrspace(4)* %g to i64 | ||
%shift = lshr i64 %i, 32 | ||
ret i64 %shift | ||
} | ||
|
||
; CHECK-LABEL: @test_null | ||
; A null pointer casted to another addr space may no longer have null value. | ||
; CHECK-NOT: ret i32 0 | ||
define i32 @test_null() { | ||
%g = addrspacecast i8* null to i8 addrspace(3)* | ||
%i = ptrtoint i8 addrspace(3)* %g to i32 | ||
ret i32 %i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters