diff options
| -rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 5 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/cgp-usubo.ll | 8 | ||||
| -rw-r--r-- | llvm/test/Transforms/CodeGenPrepare/X86/overflow-intrinsics.ll | 9 |
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 |

