[llvm] r372509 - [InstCombine] add tests for icmp fold hindered by min/max; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 22 07:23:23 PDT 2019
Author: spatel
Date: Sun Sep 22 07:23:22 2019
New Revision: 372509
URL: http://llvm.org/viewvc/llvm-project?rev=372509&view=rev
Log:
[InstCombine] add tests for icmp fold hindered by min/max; NFC
Modified:
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=372509&r1=372508&r2=372509&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Sun Sep 22 07:23:22 2019
@@ -679,6 +679,42 @@ define i1 @test37_extra_uses(i32 %x, i32
ret i1 %c
}
+; TODO: Min/max pattern should not prevent the fold.
+
+define i32 @neg_max_s32(i32 %x, i32 %y) {
+; CHECK-LABEL: @neg_max_s32(
+; CHECK-NEXT: [[NX:%.*]] = sub nsw i32 0, [[X:%.*]]
+; CHECK-NEXT: [[NY:%.*]] = sub nsw i32 0, [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[NX]], [[NY]]
+; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 [[NY]], i32 [[NX]]
+; CHECK-NEXT: [[R:%.*]] = sub nsw i32 0, [[S]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %nx = sub nsw i32 0, %x
+ %ny = sub nsw i32 0, %y
+ %c = icmp slt i32 %nx, %ny
+ %s = select i1 %c, i32 %ny, i32 %nx
+ %r = sub nsw i32 0, %s
+ ret i32 %r
+}
+
+define <4 x i32> @neg_max_v4s32(<4 x i32> %x, <4 x i32> %y) {
+; CHECK-LABEL: @neg_max_v4s32(
+; CHECK-NEXT: [[NX:%.*]] = sub nsw <4 x i32> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT: [[NY:%.*]] = sub nsw <4 x i32> zeroinitializer, [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp sgt <4 x i32> [[NX]], [[NY]]
+; CHECK-NEXT: [[S:%.*]] = select <4 x i1> [[C]], <4 x i32> [[NX]], <4 x i32> [[NY]]
+; CHECK-NEXT: [[R:%.*]] = sub <4 x i32> zeroinitializer, [[S]]
+; CHECK-NEXT: ret <4 x i32> [[R]]
+;
+ %nx = sub nsw <4 x i32> zeroinitializer, %x
+ %ny = sub nsw <4 x i32> zeroinitializer, %y
+ %c = icmp sgt <4 x i32> %nx, %ny
+ %s = select <4 x i1> %c, <4 x i32> %nx, <4 x i32> %ny
+ %r = sub <4 x i32> zeroinitializer, %s
+ ret <4 x i32> %r
+}
+
; X - Y > X - Z -> Z > Y if there is no overflow.
define i1 @test38(i32 %x, i32 %y, i32 %z) {
; CHECK-LABEL: @test38(
More information about the llvm-commits
mailing list