forked from OSchip/llvm-project
Fix AArch64ConditionOptimizer
Summary: This pass may modify the Cmp operands. However, the flag reg may be used by both the branch and CSEL. Modifying CMP will have side effect on CSEL. Reviewers: t.p.northover Subscribers: llvm-commits, aemerson, rengolin Differential Revision: http://reviews.llvm.org/D16147 llvm-svn: 257844
This commit is contained in:
parent
95e363d0de
commit
038393bba0
|
@ -144,10 +144,18 @@ MachineInstr *AArch64ConditionOptimizer::findSuitableCompare(
|
|||
if (I->getOpcode() != AArch64::Bcc)
|
||||
return nullptr;
|
||||
|
||||
// Since we may modify cmp of this MBB, make sure NZCV does not live out.
|
||||
for (auto SuccBB : MBB->successors())
|
||||
if (SuccBB->isLiveIn(AArch64::NZCV))
|
||||
return nullptr;
|
||||
|
||||
// Now find the instruction controlling the terminator.
|
||||
for (MachineBasicBlock::iterator B = MBB->begin(); I != B;) {
|
||||
--I;
|
||||
assert(!I->isTerminator() && "Spurious terminator");
|
||||
// Check if there is any use of NZCV between CMP and Bcc.
|
||||
if (I->readsRegister(AArch64::NZCV))
|
||||
return nullptr;
|
||||
switch (I->getOpcode()) {
|
||||
// cmp is an alias for subs with a dead destination register.
|
||||
case AArch64::SUBSWri:
|
||||
|
|
|
@ -429,6 +429,42 @@ falser:
|
|||
ret void
|
||||
}
|
||||
|
||||
define i32 @combine_gt_ge_sel(i64 %v, i64* %p) #0 {
|
||||
; CHECK-LABEL: combine_gt_ge_sel
|
||||
; CHECK: ldr [[reg1:w[0-9]*]],
|
||||
; CHECK: cmp [[reg1]], #0
|
||||
; CHECK: csel {{.*}}, gt
|
||||
entry:
|
||||
%0 = load i32, i32* @a, align 4
|
||||
%cmp = icmp sgt i32 %0, 0
|
||||
%m = select i1 %cmp, i64 %v, i64 0
|
||||
store i64 %m, i64* %p
|
||||
br i1 %cmp, label %lor.lhs.false, label %land.lhs.true
|
||||
|
||||
land.lhs.true: ; preds = %entry
|
||||
%1 = load i32, i32* @b, align 4
|
||||
%2 = load i32, i32* @c, align 4
|
||||
%cmp1 = icmp eq i32 %1, %2
|
||||
br i1 %cmp1, label %return, label %land.lhs.true3
|
||||
|
||||
lor.lhs.false: ; preds = %entry
|
||||
%cmp2 = icmp sgt i32 %0, 1
|
||||
br i1 %cmp2, label %land.lhs.true3, label %if.end
|
||||
|
||||
land.lhs.true3: ; preds = %lor.lhs.false, %land.lhs.true
|
||||
%3 = load i32, i32* @b, align 4
|
||||
%4 = load i32, i32* @d, align 4
|
||||
%cmp4 = icmp eq i32 %3, %4
|
||||
br i1 %cmp4, label %return, label %if.end
|
||||
|
||||
if.end: ; preds = %land.lhs.true3, %lor.lhs.false
|
||||
br label %return
|
||||
|
||||
return: ; preds = %if.end, %land.lhs.true3, %land.lhs.true
|
||||
%retval.0 = phi i32 [ 0, %if.end ], [ 1, %land.lhs.true3 ], [ 1, %land.lhs.true ]
|
||||
ret i32 %retval.0
|
||||
}
|
||||
|
||||
declare i32 @zoo(i32)
|
||||
|
||||
declare double @yoo(i32)
|
||||
|
|
Loading…
Reference in New Issue