Skip to content

Commit 59289a8

Browse files
rickyztstellar
authored andcommitted
[AA] Handle callbr instructions in alias analysis
Before this change, AAResults::getModRefInfo() was missing a case for callbr instructions (asm goto), which may read/write memory. In PR52735, this led to a miscompile where a load was incorrect eliminated. Add this missing case, as well as an assert verifying that all memory-accessing instructions are handled properly. Fixes #52735. Differential Revision: https://reviews.llvm.org/D115992 (cherry picked from commit 9927a06)
1 parent 5b2990a commit 59289a8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

llvm/lib/Analysis/AliasAnalysis.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,14 +697,16 @@ ModRefInfo AAResults::getModRefInfo(const Instruction *I,
697697
case Instruction::AtomicRMW:
698698
return getModRefInfo((const AtomicRMWInst *)I, Loc, AAQIP);
699699
case Instruction::Call:
700-
return getModRefInfo((const CallInst *)I, Loc, AAQIP);
700+
case Instruction::CallBr:
701701
case Instruction::Invoke:
702-
return getModRefInfo((const InvokeInst *)I, Loc, AAQIP);
702+
return getModRefInfo((const CallBase *)I, Loc, AAQIP);
703703
case Instruction::CatchPad:
704704
return getModRefInfo((const CatchPadInst *)I, Loc, AAQIP);
705705
case Instruction::CatchRet:
706706
return getModRefInfo((const CatchReturnInst *)I, Loc, AAQIP);
707707
default:
708+
assert(!I->mayReadOrWriteMemory() &&
709+
"Unhandled memory access instruction!");
708710
return ModRefInfo::NoModRef;
709711
}
710712
}

llvm/test/Analysis/BasicAA/pr52735.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: opt %s -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2+
;
3+
; Generated from:
4+
;
5+
; int foo() {
6+
; int v;
7+
; asm goto("movl $1, %0" : "=m"(v)::: out);
8+
; out:
9+
; return v;
10+
; }
11+
12+
target triple = "x86_64-unknown-linux-gnu"
13+
14+
; CHECK: MayAlias: i32* %v, void (i32*, i8*)* asm "movl $$1, $0", "=*m,X,~{dirflag},~{fpsr},~{flags}"
15+
16+
define dso_local i32 @foo() {
17+
entry:
18+
%v = alloca i32, align 4
19+
%0 = bitcast i32* %v to i8*
20+
callbr void asm "movl $$1, $0", "=*m,X,~{dirflag},~{fpsr},~{flags}"(i32* nonnull %v, i8* blockaddress(@foo, %out))
21+
to label %asm.fallthrough [label %out]
22+
23+
asm.fallthrough:
24+
br label %out
25+
26+
out:
27+
%1 = load i32, i32* %v, align 4
28+
ret i32 %1
29+
}

0 commit comments

Comments
 (0)