[llvm] r354519 - [CGP] match a special-case of unsigned subtract overflow
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 20 13:23:04 PST 2019
Author: spatel
Date: Wed Feb 20 13:23:04 2019
New Revision: 354519
URL: http://llvm.org/viewvc/llvm-project?rev=354519&view=rev
Log:
[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
Modified:
llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
llvm/trunk/test/CodeGen/X86/cgp-usubo.ll
llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll
Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=354519&r1=354518&r2=354519&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Wed Feb 20 13:23:04 2019
@@ -1228,6 +1228,11 @@ static bool combineToUSubWithOverflow(Cm
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;
Modified: llvm/trunk/test/CodeGen/X86/cgp-usubo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/cgp-usubo.ll?rev=354519&r1=354518&r2=354519&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/cgp-usubo.ll (original)
+++ llvm/trunk/test/CodeGen/X86/cgp-usubo.ll Wed Feb 20 13:23:04 2019
@@ -111,11 +111,9 @@ define i1 @usubo_eq_constant1_op1_i32(i3
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
Modified: llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll?rev=354519&r1=354518&r2=354519&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll Wed Feb 20 13:23:04 2019
@@ -285,10 +285,11 @@ define i1 @usubo_eq_constant1_op1_i32(i3
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
More information about the llvm-commits
mailing list