Skip to content

Commit 2685951

Browse files
author
git apple-llvm automerger
committed
Merge commit '26ae724bfd52' from apple/stable/20200714 into swift/master
2 parents e56ea28 + 26ae724 commit 2685951

File tree

6 files changed

+153
-51
lines changed

6 files changed

+153
-51
lines changed

llvm/include/llvm/ADT/SmallPtrSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ class SmallPtrSetImpl : public SmallPtrSetImplBase {
378378
iterator find(ConstPtrType Ptr) const {
379379
return makeIterator(find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)));
380380
}
381+
bool contains(ConstPtrType Ptr) const {
382+
return find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)) != EndPointer();
383+
}
381384

382385
template <typename IterT>
383386
void insert(IterT I, IterT E) {

llvm/lib/CodeGen/PHIEliminationUtils.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,35 @@ llvm::findPHICopyInsertPoint(MachineBasicBlock* MBB, MachineBasicBlock* SuccMBB,
2727
// Usually, we just want to insert the copy before the first terminator
2828
// instruction. However, for the edge going to a landing pad, we must insert
2929
// the copy before the call/invoke instruction. Similarly for an INLINEASM_BR
30-
// going to an indirect target.
31-
if (!SuccMBB->isEHPad() && !SuccMBB->isInlineAsmBrIndirectTarget())
30+
// going to an indirect target. This is similar to SplitKit.cpp's
31+
// computeLastInsertPoint, and similarly assumes that there cannot be multiple
32+
// instructions that are Calls with EHPad successors or INLINEASM_BR in a
33+
// block.
34+
bool EHPadSuccessor = SuccMBB->isEHPad();
35+
if (!EHPadSuccessor && !SuccMBB->isInlineAsmBrIndirectTarget())
3236
return MBB->getFirstTerminator();
3337

34-
// Discover any defs/uses in this basic block.
35-
SmallPtrSet<MachineInstr*, 8> DefUsesInMBB;
38+
// Discover any defs in this basic block.
39+
SmallPtrSet<MachineInstr *, 8> DefsInMBB;
3640
MachineRegisterInfo& MRI = MBB->getParent()->getRegInfo();
37-
for (MachineInstr &RI : MRI.reg_instructions(SrcReg)) {
41+
for (MachineInstr &RI : MRI.def_instructions(SrcReg))
3842
if (RI.getParent() == MBB)
39-
DefUsesInMBB.insert(&RI);
40-
}
43+
DefsInMBB.insert(&RI);
4144

42-
MachineBasicBlock::iterator InsertPoint;
43-
if (DefUsesInMBB.empty()) {
44-
// No defs. Insert the copy at the start of the basic block.
45-
InsertPoint = MBB->begin();
46-
} else if (DefUsesInMBB.size() == 1) {
47-
// Insert the copy immediately after the def/use.
48-
InsertPoint = *DefUsesInMBB.begin();
49-
++InsertPoint;
50-
} else {
51-
// Insert the copy immediately after the last def/use.
52-
InsertPoint = MBB->end();
53-
while (!DefUsesInMBB.count(&*--InsertPoint)) {}
54-
++InsertPoint;
45+
MachineBasicBlock::iterator InsertPoint = MBB->begin();
46+
// Insert the copy at the _latest_ point of:
47+
// 1. Immediately AFTER the last def
48+
// 2. Immediately BEFORE a call/inlineasm_br.
49+
for (auto I = MBB->rbegin(), E = MBB->rend(); I != E; ++I) {
50+
if (DefsInMBB.contains(&*I)) {
51+
InsertPoint = std::next(I.getReverse());
52+
break;
53+
}
54+
if ((EHPadSuccessor && I->isCall()) ||
55+
I->getOpcode() == TargetOpcode::INLINEASM_BR) {
56+
InsertPoint = I.getReverse();
57+
break;
58+
}
5559
}
5660

5761
// Make sure the copy goes after any phi nodes but before

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,32 +171,6 @@ static cl::opt<unsigned> SwitchPeelThreshold(
171171
// store [4096 x i8] %data, [4096 x i8]* %buffer
172172
static const unsigned MaxParallelChains = 64;
173173

174-
// Return the calling convention if the Value passed requires ABI mangling as it
175-
// is a parameter to a function or a return value from a function which is not
176-
// an intrinsic.
177-
static Optional<CallingConv::ID> getABIRegCopyCC(const Value *V) {
178-
if (auto *R = dyn_cast<ReturnInst>(V))
179-
return R->getParent()->getParent()->getCallingConv();
180-
181-
if (auto *CI = dyn_cast<CallInst>(V)) {
182-
const bool IsInlineAsm = CI->isInlineAsm();
183-
const bool IsIndirectFunctionCall =
184-
!IsInlineAsm && !CI->getCalledFunction();
185-
186-
// It is possible that the call instruction is an inline asm statement or an
187-
// indirect function call in which case the return value of
188-
// getCalledFunction() would be nullptr.
189-
const bool IsInstrinsicCall =
190-
!IsInlineAsm && !IsIndirectFunctionCall &&
191-
CI->getCalledFunction()->getIntrinsicID() != Intrinsic::not_intrinsic;
192-
193-
if (!IsInlineAsm && !IsInstrinsicCall)
194-
return CI->getCallingConv();
195-
}
196-
197-
return None;
198-
}
199-
200174
static SDValue getCopyFromPartsVector(SelectionDAG &DAG, const SDLoc &DL,
201175
const SDValue *Parts, unsigned NumParts,
202176
MVT PartVT, EVT ValueVT, const Value *V,
@@ -1638,7 +1612,7 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
16381612
unsigned InReg = FuncInfo.InitializeRegForValue(Inst);
16391613

16401614
RegsForValue RFV(*DAG.getContext(), TLI, DAG.getDataLayout(), InReg,
1641-
Inst->getType(), getABIRegCopyCC(V));
1615+
Inst->getType(), None);
16421616
SDValue Chain = DAG.getEntryNode();
16431617
return RFV.getCopyFromRegs(DAG, FuncInfo, getCurSDLoc(), Chain, nullptr, V);
16441618
}
@@ -5577,7 +5551,7 @@ bool SelectionDAGBuilder::EmitFuncArgumentDbgValue(
55775551
if (VMI != FuncInfo.ValueMap.end()) {
55785552
const auto &TLI = DAG.getTargetLoweringInfo();
55795553
RegsForValue RFV(V->getContext(), TLI, DAG.getDataLayout(), VMI->second,
5580-
V->getType(), getABIRegCopyCC(V));
5554+
V->getType(), None);
55815555
if (RFV.occupiesMultipleRegs()) {
55825556
splitMultiRegDbgValue(RFV.getRegsAndSizes());
55835557
return true;

llvm/test/CodeGen/ARM/pr47454.ll

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=armv8-unknown-linux-unknown -mattr=-fp16 -O0 < %s | FileCheck %s
3+
4+
declare fastcc half @getConstant()
5+
6+
declare fastcc i1 @isEqual(half %0, half %1)
7+
8+
define internal fastcc void @main() {
9+
; CHECK-LABEL: main:
10+
; CHECK: @ %bb.0: @ %Entry
11+
; CHECK-NEXT: push {r11, lr}
12+
; CHECK-NEXT: mov r11, sp
13+
; CHECK-NEXT: sub sp, sp, #16
14+
; CHECK-NEXT: mov r0, #31744
15+
; CHECK-NEXT: strh r0, [r11, #-2]
16+
; CHECK-NEXT: ldrh r0, [r11, #-2]
17+
; CHECK-NEXT: bl __gnu_h2f_ieee
18+
; CHECK-NEXT: vmov s0, r0
19+
; CHECK-NEXT: vstr s0, [sp, #8] @ 4-byte Spill
20+
; CHECK-NEXT: bl getConstant
21+
; CHECK-NEXT: vmov r0, s0
22+
; CHECK-NEXT: bl __gnu_h2f_ieee
23+
; CHECK-NEXT: vmov s0, r0
24+
; CHECK-NEXT: vmov r0, s0
25+
; CHECK-NEXT: bl __gnu_f2h_ieee
26+
; CHECK-NEXT: vldr s0, [sp, #8] @ 4-byte Reload
27+
; CHECK-NEXT: vmov r1, s0
28+
; CHECK-NEXT: str r0, [sp, #4] @ 4-byte Spill
29+
; CHECK-NEXT: mov r0, r1
30+
; CHECK-NEXT: bl __gnu_f2h_ieee
31+
; CHECK-NEXT: uxth r0, r0
32+
; CHECK-NEXT: vmov s0, r0
33+
; CHECK-NEXT: ldr r0, [sp, #4] @ 4-byte Reload
34+
; CHECK-NEXT: uxth r1, r0
35+
; CHECK-NEXT: vmov s1, r1
36+
; CHECK-NEXT: bl isEqual
37+
; CHECK-NEXT: mov sp, r11
38+
; CHECK-NEXT: pop {r11, pc}
39+
Entry:
40+
; First arg directly from constant
41+
%const = alloca half, align 2
42+
store half 0xH7C00, half* %const, align 2
43+
%arg1 = load half, half* %const, align 2
44+
; Second arg from fucntion return
45+
%arg2 = call fastcc half @getConstant()
46+
; Arguments should have equivalent mangling
47+
%result = call fastcc i1 @isEqual(half %arg1, half %arg2)
48+
ret void
49+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -O2 < %s | FileCheck %s
3+
4+
;; https://bugs.llvm.org/PR47468
5+
6+
;; PHI elimination should place copies BEFORE the inline asm, not
7+
;; after, even if the inline-asm uses as an input the same value as
8+
;; the PHI.
9+
10+
declare void @foo(i8*)
11+
12+
define void @test1(i8* %arg, i8** %mem) nounwind {
13+
; CHECK-LABEL: test1:
14+
; CHECK: # %bb.0: # %entry
15+
; CHECK-NEXT: pushq %r14
16+
; CHECK-NEXT: pushq %rbx
17+
; CHECK-NEXT: pushq %rax
18+
; CHECK-NEXT: movq %rsi, %r14
19+
; CHECK-NEXT: .Ltmp0: # Block address taken
20+
; CHECK-NEXT: .LBB0_1: # %loop
21+
; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
22+
; CHECK-NEXT: movq (%r14), %rbx
23+
; CHECK-NEXT: callq foo
24+
; CHECK-NEXT: movq %rbx, %rdi
25+
; CHECK-NEXT: #APP
26+
; CHECK-NEXT: #NO_APP
27+
; CHECK-NEXT: # %bb.2: # %end
28+
; CHECK-NEXT: addq $8, %rsp
29+
; CHECK-NEXT: popq %rbx
30+
; CHECK-NEXT: popq %r14
31+
; CHECK-NEXT: retq
32+
entry:
33+
br label %loop
34+
35+
loop:
36+
%a = phi i8* [ %arg, %entry ], [ %b, %loop ]
37+
%b = load i8*, i8** %mem, align 8
38+
call void @foo(i8* %a)
39+
callbr void asm sideeffect "", "*m,X"(i8* %b, i8* blockaddress(@test1, %loop))
40+
to label %end [label %loop]
41+
42+
end:
43+
ret void
44+
}

llvm/unittests/ADT/SmallPtrSetTest.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ TEST(SmallPtrSetTest, ConstTest) {
313313
IntSet.insert(B);
314314
EXPECT_EQ(IntSet.count(B), 1u);
315315
EXPECT_EQ(IntSet.count(C), 1u);
316-
EXPECT_NE(IntSet.find(B), IntSet.end());
317-
EXPECT_NE(IntSet.find(C), IntSet.end());
316+
EXPECT_TRUE(IntSet.contains(B));
317+
EXPECT_TRUE(IntSet.contains(C));
318318
}
319319

320320
// Verify that we automatically get the const version of PointerLikeTypeTraits
@@ -327,7 +327,7 @@ TEST(SmallPtrSetTest, ConstNonPtrTest) {
327327
TestPair Pair(&A[0], 1);
328328
IntSet.insert(Pair);
329329
EXPECT_EQ(IntSet.count(Pair), 1u);
330-
EXPECT_NE(IntSet.find(Pair), IntSet.end());
330+
EXPECT_TRUE(IntSet.contains(Pair));
331331
}
332332

333333
// Test equality comparison.
@@ -367,3 +367,31 @@ TEST(SmallPtrSetTest, EqualityComparison) {
367367
EXPECT_NE(c, e);
368368
EXPECT_NE(e, d);
369369
}
370+
371+
TEST(SmallPtrSetTest, Contains) {
372+
SmallPtrSet<int *, 2> Set;
373+
int buf[4] = {0, 11, 22, 11};
374+
EXPECT_FALSE(Set.contains(&buf[0]));
375+
EXPECT_FALSE(Set.contains(&buf[1]));
376+
377+
Set.insert(&buf[0]);
378+
Set.insert(&buf[1]);
379+
EXPECT_TRUE(Set.contains(&buf[0]));
380+
EXPECT_TRUE(Set.contains(&buf[1]));
381+
EXPECT_FALSE(Set.contains(&buf[3]));
382+
383+
Set.insert(&buf[1]);
384+
EXPECT_TRUE(Set.contains(&buf[0]));
385+
EXPECT_TRUE(Set.contains(&buf[1]));
386+
EXPECT_FALSE(Set.contains(&buf[3]));
387+
388+
Set.erase(&buf[1]);
389+
EXPECT_TRUE(Set.contains(&buf[0]));
390+
EXPECT_FALSE(Set.contains(&buf[1]));
391+
392+
Set.insert(&buf[1]);
393+
Set.insert(&buf[2]);
394+
EXPECT_TRUE(Set.contains(&buf[0]));
395+
EXPECT_TRUE(Set.contains(&buf[1]));
396+
EXPECT_TRUE(Set.contains(&buf[2]));
397+
}

0 commit comments

Comments
 (0)