summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2015-07-28 22:42:32 +0000
committerTim Northover <tnorthover@apple.com>2015-07-28 22:42:32 +0000
commit17ae83a25f283d491904f74c759c30f27dbc8225 (patch)
treede22905d0f1afb87b9ba96993fe4bfe311af3485 /llvm
parent0dae64a554fb0582e76d2ed1bd41cebb40a3de65 (diff)
downloadbcm5719-llvm-17ae83a25f283d491904f74c759c30f27dbc8225.tar.gz
bcm5719-llvm-17ae83a25f283d491904f74c759c30f27dbc8225.zip
AArch64: be careful of large immediates when optimising cmps.
llvm-svn: 243492
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp17
-rw-r--r--llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll26
2 files changed, 38 insertions, 5 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp b/llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
index b9e41c61def..99a5eaa7aef 100644
--- a/llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ConditionOptimizer.cpp
@@ -154,11 +154,18 @@ MachineInstr *AArch64ConditionOptimizer::findSuitableCompare(
// cmn is an alias for adds with a dead destination register.
case AArch64::ADDSWri:
case AArch64::ADDSXri:
- if (MRI->use_empty(I->getOperand(0).getReg()))
- return I;
-
- DEBUG(dbgs() << "Destination of cmp is not dead, " << *I << '\n');
- return nullptr;
+ if (!I->getOperand(2).isImm()) {
+ DEBUG(dbgs() << "Immediate of cmp is symbolic, " << *I << '\n');
+ return nullptr;
+ } else if (I->getOperand(2).getImm() << I->getOperand(3).getImm() >=
+ 0xfff) {
+ DEBUG(dbgs() << "Immediate of cmp may be out of range, " << *I << '\n');
+ return nullptr;
+ } else if (!MRI->use_empty(I->getOperand(0).getReg())) {
+ DEBUG(dbgs() << "Destination of cmp is not dead, " << *I << '\n');
+ return nullptr;
+ }
+ return I;
// Prevent false positive case like:
// cmp w19, #0
diff --git a/llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll b/llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
index c78fabac618..004267f4e4e 100644
--- a/llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
+++ b/llvm/test/CodeGen/AArch64/combine-comparisons-by-cse.ll
@@ -403,6 +403,32 @@ return: ; preds = %land.lhs.true, %con
ret i32 %retval.0
}
+define void @cmp_shifted(i32 %in, i32 %lhs, i32 %rhs) {
+; CHECK-LABEL: cmp_shifted:
+; CHECK: cmp w0, #1
+; [...]
+; CHECK: cmp w0, #2, lsl #12
+
+ %tst_low = icmp sgt i32 %in, 0
+ br i1 %tst_low, label %true, label %false
+
+true:
+ call i32 @zoo(i32 128)
+ ret void
+
+false:
+ %tst = icmp sgt i32 %in, 8191
+ br i1 %tst, label %truer, label %falser
+
+truer:
+ call i32 @zoo(i32 42)
+ ret void
+
+falser:
+ call i32 @zoo(i32 1)
+ ret void
+}
+
declare i32 @zoo(i32)
declare double @yoo(i32)
OpenPOWER on IntegriCloud