Skip to content

Commit 3a8d7fe

Browse files
vtjnashvchuravy
authored andcommitted
[SimplifyCFG] teach simplifycfg not to introduce ptrtoint for NI pointers
SimplifyCFG expects to be able to cast both sides to an int, if either side can be case to an int, but this is not desirable or legal, in general, per D104547. Spotted in JuliaLang/julia#45702 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D128670
1 parent 31fbdab commit 3a8d7fe

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ static bool dominatesMergePoint(Value *V, BasicBlock *BB,
473473
static ConstantInt *GetConstantInt(Value *V, const DataLayout &DL) {
474474
// Normal constant int.
475475
ConstantInt *CI = dyn_cast<ConstantInt>(V);
476-
if (CI || !isa<Constant>(V) || !V->getType()->isPointerTy())
476+
if (CI || !isa<Constant>(V) || !V->getType()->isPointerTy() ||
477+
DL.isNonIntegralPointerType(V->getType()))
477478
return CI;
478479

479480
// This is some kind of pointer constant. Turn it into a pointer-sized
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: opt -passes=simplifycfg -S < %s | FileCheck %s
2+
3+
target datalayout = "ni:1"
4+
5+
define void @test_01(i64 addrspace(1)* align 8 %ptr) {
6+
; CHECK-LABEL: @test_01(
7+
; CHECK-NOT: ptrtoint
8+
; CHECK-NEXT: icmp eq i64 addrspace(1)* %ptr, null
9+
; CHECK-NOT: ptrtoint
10+
%cond1 = icmp eq i64 addrspace(1)* %ptr, null
11+
%cond2 = icmp eq i64 addrspace(1)* %ptr, null
12+
br i1 %cond1, label %true1, label %false1
13+
14+
true1:
15+
br i1 %cond2, label %true2, label %false2
16+
17+
false1:
18+
store i64 1, i64 addrspace(1)* %ptr, align 8
19+
br label %true1
20+
21+
true2:
22+
store i64 2, i64 addrspace(1)* %ptr, align 8
23+
ret void
24+
25+
false2:
26+
store i64 3, i64 addrspace(1)* %ptr, align 8
27+
ret void
28+
}

0 commit comments

Comments
 (0)