summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-02-20 21:23:04 +0000
committerSanjay Patel <spatel@rotateright.com>2019-02-20 21:23:04 +0000
commit198cc305e985accb3ba74f64e38fd5b3146fe6f4 (patch)
tree74ed449a1f6500d3f3747747f006fa5f2aeea9e2
parent48cf37b55cc956df03c61bc41eb54fc4f582fef6 (diff)
downloadbcm5719-llvm-198cc305e985accb3ba74f64e38fd5b3146fe6f4.tar.gz
bcm5719-llvm-198cc305e985accb3ba74f64e38fd5b3146fe6f4.zip
[CGP] match a special-case of unsigned subtract overflow
This is the 'sub0' (negate) pattern from PR31754: https://bugs.llvm.org/show_bug.cgi?id=31754 llvm-svn: 354519
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp5
-rw-r--r--llvm/test/CodeGen/X86/cgp-usubo.ll8
-rw-r--r--llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll9
3 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 20a2ae1233c..e9611392058 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1228,6 +1228,11 @@ static bool combineToUSubWithOverflow(CmpInst *Cmp, const TargetLowering &TLI,
B = ConstantInt::get(B->getType(), 1);
Pred = ICmpInst::ICMP_ULT;
}
+ // Convert special-case: (A != 0) is the same as (0 u< A).
+ if (Pred == ICmpInst::ICMP_NE && match(B, m_ZeroInt())) {
+ std::swap(A, B);
+ Pred = ICmpInst::ICMP_ULT;
+ }
if (Pred != ICmpInst::ICMP_ULT)
return false;
diff --git a/llvm/test/CodeGen/X86/cgp-usubo.ll b/llvm/test/CodeGen/X86/cgp-usubo.ll
index ba804282364..aa0e15b3784 100644
--- a/llvm/test/CodeGen/X86/cgp-usubo.ll
+++ b/llvm/test/CodeGen/X86/cgp-usubo.ll
@@ -111,11 +111,9 @@ define i1 @usubo_eq_constant1_op1_i32(i32 %x, i32* %p) nounwind {
define i1 @usubo_ne_constant0_op1_i32(i32 %x, i32* %p) {
; CHECK-LABEL: usubo_ne_constant0_op1_i32:
; CHECK: # %bb.0:
-; CHECK-NEXT: movl %edi, %ecx
-; CHECK-NEXT: negl %ecx
-; CHECK-NEXT: testl %edi, %edi
-; CHECK-NEXT: setne %al
-; CHECK-NEXT: movl %ecx, (%rsi)
+; CHECK-NEXT: negl %edi
+; CHECK-NEXT: setb %al
+; CHECK-NEXT: movl %edi, (%rsi)
; CHECK-NEXT: retq
%s = sub i32 0, %x
%ov = icmp ne i32 %x, 0
diff --git a/llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll b/llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll
index 5107e833ecf..4b0bafacaf4 100644
--- a/llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll
+++ b/llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll
@@ -285,10 +285,11 @@ define i1 @usubo_eq_constant1_op1_i32(i32 %x, i32* %p) {
define i1 @usubo_ne_constant0_op1_i32(i32 %x, i32* %p) {
; CHECK-LABEL: @usubo_ne_constant0_op1_i32(
-; CHECK-NEXT: [[S:%.*]] = sub i32 0, [[X:%.*]]
-; CHECK-NEXT: [[OV:%.*]] = icmp ne i32 [[X]], 0
-; CHECK-NEXT: store i32 [[S]], i32* [[P:%.*]]
-; CHECK-NEXT: ret i1 [[OV]]
+; CHECK-NEXT: [[TMP1:%.*]] = call { i32, i1 } @llvm.usub.with.overflow.i32(i32 0, i32 [[X:%.*]])
+; CHECK-NEXT: [[MATH:%.*]] = extractvalue { i32, i1 } [[TMP1]], 0
+; CHECK-NEXT: [[OV1:%.*]] = extractvalue { i32, i1 } [[TMP1]], 1
+; CHECK-NEXT: store i32 [[MATH]], i32* [[P:%.*]]
+; CHECK-NEXT: ret i1 [[OV1]]
;
%s = sub i32 0, %x
%ov = icmp ne i32 %x, 0
OpenPOWER on IntegriCloud