Skip to content

Commit 4232fb3

Browse files
committedAug 9, 2015
[PHITransAddr] Don't assume that instruction operands are translatable
We can only PHI translate instructions. In our attempt to PHI translate a bitcast, we attempt to translate its operand; however, the operand might be an argument or a global instead of an instruction. Benignly bail out when this happens. This fixes PR24397. Differential Revision: http://reviews.llvm.org/D11879 llvm-svn: 244418
1 parent 86cc829 commit 4232fb3

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed
 

‎llvm/lib/Analysis/PHITransAddr.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,10 @@ InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
374374
if (!Tmp.PHITranslateValue(CurBB, PredBB, &DT, /*MustDominate=*/true))
375375
return Tmp.getAddr();
376376

377-
// If we don't have an available version of this value, it must be an
378-
// instruction.
379-
Instruction *Inst = cast<Instruction>(InVal);
377+
// We don't need to PHI translate values which aren't instructions.
378+
auto *Inst = dyn_cast<Instruction>(InVal);
379+
if (!Inst)
380+
return nullptr;
380381

381382
// Handle cast of PHI translatable value.
382383
if (CastInst *Cast = dyn_cast<CastInst>(Inst)) {

‎llvm/test/Transforms/GVN/pr24397.ll

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt -basicaa -gvn -disable-output < %s
2+
3+
target triple = "x86_64-unknown-linux-gnu"
4+
5+
define i64 @foo(i64** %arrayidx) {
6+
entry:
7+
%p = load i64*, i64** %arrayidx, align 8
8+
%cmpnull = icmp eq i64* %p, null
9+
br label %BB2
10+
11+
entry2: ; No predecessors!
12+
br label %BB2
13+
14+
BB2: ; preds = %entry2, %entry
15+
%bc = bitcast i64** %arrayidx to i64*
16+
%load = load i64, i64* %bc, align 8
17+
ret i64 %load
18+
}

0 commit comments

Comments
 (0)