[llvm] r257844 - Fix AArch64ConditionOptimizer
Weiming Zhao via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 14 16:06:58 PST 2016
Author: weimingz
Date: Thu Jan 14 18:06:58 2016
New Revision: 257844
URL: http://llvm.org/viewvc/llvm-project?rev=257844&view=rev
Log:
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
Modified:
llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
llvm/trunk/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
Modified: llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp?rev=257844&r1=257843&r2=257844&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64ConditionOptimizer.cpp Thu Jan 14 18:06:58 2016
@@ -144,10 +144,18 @@ MachineInstr *AArch64ConditionOptimizer:
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:
Modified: llvm/trunk/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/combine-comparisons-by-cse.ll?rev=257844&r1=257843&r2=257844&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/combine-comparisons-by-cse.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/combine-comparisons-by-cse.ll Thu Jan 14 18:06:58 2016
@@ -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)
More information about the llvm-commits
mailing list