AArch64: Don't call getIterator() on iterators

Remove an unnecessary round-trip:

    iterator => operator->() => getIterator()

In some cases, the iterator is end(), so the dereference of operator->
is invalid (UB).

The testcase only crashes with r278974 (currently reverted to
investigate this), which adds an assertion for invalid dereferences of
ilist nodes.

Fixes PR29035.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279104 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2016-08-18 17:58:09 +00:00
parent 8970377ddc
commit 92e6c942c5
2 changed files with 30 additions and 2 deletions

View File

@ -156,8 +156,7 @@ bool AArch64RedundantCopyElimination::optimizeCopy(MachineBasicBlock *MBB) {
MBB->addLiveIn(TargetReg);
// Clear any kills of TargetReg between CompBr and the last removed COPY.
for (MachineInstr &MMI :
make_range(MBB->begin()->getIterator(), LastChange->getIterator()))
for (MachineInstr &MMI : make_range(MBB->begin(), LastChange))
MMI.clearRegisterKills(SmallestDef, TRI);
return true;

View File

@ -0,0 +1,29 @@
; RUN: llc < %s | FileCheck %s
; Make sure we don't crash in AArch64RedundantCopyElimination when a
; MachineBasicBlock is empty. PR29035.
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"
declare i8* @bar()
; CHECK-LABEL: foo:
; CHECK: tbz
; CHECK: orr
; CHECK: ret
; CHECK: bl bar
; CHECK: cbnz
; CHECK: ret
define i1 @foo(i1 %start) {
entry:
br i1 %start, label %cleanup, label %if.end
if.end: ; preds = %if.end, %entry
%call = tail call i8* @bar()
%cmp = icmp eq i8* %call, null
br i1 %cmp, label %cleanup, label %if.end
cleanup: ; preds = %if.end, %entry
%retval.0 = phi i1 [ true, %entry ], [ false, %if.end ]
ret i1 %retval.0
}