llvm.org GIT mirror llvm / fe9291f
[EarlyCSE] Handle calls with no MemorySSA info. Summary: When checking for memory dependencies between calls using MemorySSA, handle cases where the calls have no MemoryAccess associated with them because the AA analysis being used has determined that the call does not read/write memory. Fixes PR33756 Reviewers: dberlin, davide Subscribers: mcrosier, llvm-commits, Prazek Differential Revision: https://reviews.llvm.org/D35317 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308051 91177308-0d34-0410-b5e6-96231b3b80d8 Geoff Berry 2 years ago
2 changed file(s) with 40 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
561561 if (!MSSA)
562562 return false;
563563
564 // If MemorySSA has determined that one of EarlierInst or LaterInst does not
565 // read/write memory, then we can safely return true here.
566 // FIXME: We could be more aggressive when checking doesNotAccessMemory(),
567 // onlyReadsMemory(), mayReadFromMemory(), and mayWriteToMemory() in this pass
568 // by also checking the MemorySSA MemoryAccess on the instruction. Initial
569 // experiments suggest this isn't worthwhile, at least for C/C++ code compiled
570 // with the default optimization pipeline.
571 auto *EarlierMA = MSSA->getMemoryAccess(EarlierInst);
572 if (!EarlierMA)
573 return true;
574 auto *LaterMA = MSSA->getMemoryAccess(LaterInst);
575 if (!LaterMA)
576 return true;
577
564578 // Since we know LaterDef dominates LaterInst and EarlierInst dominates
565579 // LaterInst, if LaterDef dominates EarlierInst then it can't occur between
566580 // EarlierInst and LaterInst and neither can any other write that potentially
567581 // clobbers LaterInst.
568582 MemoryAccess *LaterDef =
569583 MSSA->getWalker()->getClobberingMemoryAccess(LaterInst);
570 return MSSA->dominates(LaterDef, MSSA->getMemoryAccess(EarlierInst));
584 return MSSA->dominates(LaterDef, EarlierMA);
571585 }
572586
573587 bool EarlyCSE::processNode(DomTreeNode *Node) {
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -S -globals-aa -early-cse-memssa | FileCheck %s
2
3 define i16 @f1() readonly {
4 ret i16 0
5 }
6
7 declare void @f2()
8
9 ; Check that EarlyCSE correctly handles function calls that don't have
10 ; a MemoryAccess. In this case the calls to @f1 have no
11 ; MemoryAccesses since globals-aa determines that @f1 doesn't
12 ; read/write memory at all.
13
14 define void @f3() {
15 ; CHECK-LABEL: @f3(
16 ; CHECK-NEXT: [[CALL1:%.*]] = call i16 @f1()
17 ; CHECK-NEXT: call void @f2()
18 ; CHECK-NEXT: ret void
19 ;
20 %call1 = call i16 @f1()
21 call void @f2()
22 %call2 = call i16 @f1()
23 ret void
24 }