[llvm] r356520 - [InstSimplify] Add additional cmp of abs without nsw tests; NFC
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 14:12:21 PDT 2019
Author: nikic
Date: Tue Mar 19 14:12:21 2019
New Revision: 356520
URL: http://llvm.org/viewvc/llvm-project?rev=356520&view=rev
Log:
[InstSimplify] Add additional cmp of abs without nsw tests; NFC
Modified:
llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll
Modified: llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll?rev=356520&r1=356519&r2=356520&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/icmp-abs-nabs.ll Tue Mar 19 14:12:21 2019
@@ -147,6 +147,37 @@ define i1 @abs_nsw_is_not_negative_wrong
ret i1 %r
}
+; Even if we don't have nsw, the range is still limited in the unsigned domain.
+define i1 @abs_positive_or_signed_min(i32 %x) {
+; CHECK-LABEL: @abs_positive_or_signed_min(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X]]
+; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[NEGX]], i32 [[X]]
+; CHECK-NEXT: [[R:%.*]] = icmp ult i32 [[ABS]], -2147483647
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %cmp = icmp slt i32 %x, 0
+ %negx = sub i32 0, %x
+ %abs = select i1 %cmp, i32 %negx, i32 %x
+ %r = icmp ult i32 %abs, 2147483649
+ ret i1 %r
+}
+
+define i1 @abs_positive_or_signed_min_reduced_range(i32 %x) {
+; CHECK-LABEL: @abs_positive_or_signed_min_reduced_range(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
+; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X]]
+; CHECK-NEXT: [[ABS:%.*]] = select i1 [[CMP]], i32 [[NEGX]], i32 [[X]]
+; CHECK-NEXT: [[R:%.*]] = icmp ult i32 [[ABS]], -2147483648
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %cmp = icmp slt i32 %x, 0
+ %negx = sub i32 0, %x
+ %abs = select i1 %cmp, i32 %negx, i32 %x
+ %r = icmp ult i32 %abs, 2147483648
+ ret i1 %r
+}
+
; This is canonical form for this IR. For nabs(), we don't require 'nsw'
define i1 @nabs_is_negative_or_0(i32 %x) {
More information about the llvm-commits
mailing list