[llvm] 69f4cea - [InstCombine] add tests for select --> copysign; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 13 12:39:58 PST 2020
Author: Sanjay Patel
Date: 2020-01-13T15:39:24-05:00
New Revision: 69f4cea413991a2a96635c58272bd4205f3e0c36
URL: https://github.com/llvm/llvm-project/commit/69f4cea413991a2a96635c58272bd4205f3e0c36
DIFF: https://github.com/llvm/llvm-project/commit/69f4cea413991a2a96635c58272bd4205f3e0c36.diff
LOG: [InstCombine] add tests for select --> copysign; NFC
This is testing for another (possibly final) transform suggested in:
https://bugs.llvm.org/show_bug.cgi?id=44153
Added:
Modified:
llvm/test/Transforms/InstCombine/select.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll
index 332b29d103c0..cfcae9f4c855 100644
--- a/llvm/test/Transforms/InstCombine/select.ll
+++ b/llvm/test/Transforms/InstCombine/select.ll
@@ -1532,3 +1532,111 @@ define <2 x i32> @test_shl_zext_bool_vec(<2 x i1> %t) {
%r = select <2 x i1> %t, <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer
ret <2 x i32> %r
}
+
+define float @copysign1(float %x) {
+; CHECK-LABEL: @copysign1(
+; CHECK-NEXT: [[I:%.*]] = bitcast float [[X:%.*]] to i32
+; CHECK-NEXT: [[ISPOS:%.*]] = icmp sgt i32 [[I]], -1
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISPOS]], float 1.000000e+00, float -1.000000e+00
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast float %x to i32
+ %ispos = icmp sgt i32 %i, -1
+ %r = select i1 %ispos, float 1.0, float -1.0
+ ret float %r
+}
+
+define <2 x float> @copysign2(<2 x float> %x) {
+; CHECK-LABEL: @copysign2(
+; CHECK-NEXT: [[I:%.*]] = bitcast <2 x float> [[X:%.*]] to <2 x i32>
+; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt <2 x i32> [[I]], zeroinitializer
+; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[ISNEG]], <2 x float> <float 4.200000e+01, float 4.200000e+01>, <2 x float> <float -4.200000e+01, float -4.200000e+01>
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %i = bitcast <2 x float> %x to <2 x i32>
+ %isneg = icmp slt <2 x i32> %i, zeroinitializer
+ %r = select <2 x i1> %isneg, <2 x float> <float 42.0, float 42.0>, <2 x float> <float -42.0, float -42.0>
+ ret <2 x float> %r
+}
+
+define float @copysign3(float %x) {
+; CHECK-LABEL: @copysign3(
+; CHECK-NEXT: [[I:%.*]] = bitcast float [[X:%.*]] to i32
+; CHECK-NEXT: [[ISPOS:%.*]] = icmp sgt i32 [[I]], -1
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISPOS]], float -4.300000e+01, float 4.300000e+01
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast float %x to i32
+ %ispos = icmp ult i32 %i, 2147483648
+ %r = select i1 %ispos, float -43.0, float 43.0
+ ret float %r
+}
+
+define float @copysign4(float %x) {
+; CHECK-LABEL: @copysign4(
+; CHECK-NEXT: [[I:%.*]] = bitcast float [[X:%.*]] to i32
+; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[I]], 0
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISNEG]], float -4.400000e+01, float 4.400000e+01
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast float %x to i32
+ %isneg = icmp ugt i32 %i, 2147483647
+ %r = select i1 %isneg, float -44.0, float 44.0
+ ret float %r
+}
+
+declare void @use1(i1)
+
+define float @copysign_extra_use(float %x) {
+; CHECK-LABEL: @copysign_extra_use(
+; CHECK-NEXT: [[I:%.*]] = bitcast float [[X:%.*]] to i32
+; CHECK-NEXT: [[ISNEG:%.*]] = icmp slt i32 [[I]], 0
+; CHECK-NEXT: call void @use1(i1 [[ISNEG]])
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISNEG]], float -4.400000e+01, float 4.400000e+01
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast float %x to i32
+ %isneg = icmp ugt i32 %i, 2147483647
+ call void @use1(i1 %isneg)
+ %r = select i1 %isneg, float -44.0, float 44.0
+ ret float %r
+}
+
+define float @copysign_type_mismatch(double %x) {
+; CHECK-LABEL: @copysign_type_mismatch(
+; CHECK-NEXT: [[I:%.*]] = bitcast double [[X:%.*]] to i64
+; CHECK-NEXT: [[ISPOS:%.*]] = icmp sgt i64 [[I]], -1
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISPOS]], float 1.000000e+00, float -1.000000e+00
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast double %x to i64
+ %ispos = icmp sgt i64 %i, -1
+ %r = select i1 %ispos, float 1.0, float -1.0
+ ret float %r
+}
+
+define float @copysign_wrong_cmp(float %x) {
+; CHECK-LABEL: @copysign_wrong_cmp(
+; CHECK-NEXT: [[I:%.*]] = bitcast float [[X:%.*]] to i32
+; CHECK-NEXT: [[ISPOS:%.*]] = icmp sgt i32 [[I]], 0
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISPOS]], float 1.000000e+00, float -1.000000e+00
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast float %x to i32
+ %ispos = icmp sgt i32 %i, 0
+ %r = select i1 %ispos, float 1.0, float -1.0
+ ret float %r
+}
+
+define float @copysign_wrong_const(float %x) {
+; CHECK-LABEL: @copysign_wrong_const(
+; CHECK-NEXT: [[I:%.*]] = bitcast float [[X:%.*]] to i32
+; CHECK-NEXT: [[ISPOS:%.*]] = icmp sgt i32 [[I]], -1
+; CHECK-NEXT: [[R:%.*]] = select i1 [[ISPOS]], float 2.000000e+00, float -1.000000e+00
+; CHECK-NEXT: ret float [[R]]
+;
+ %i = bitcast float %x to i32
+ %ispos = icmp sgt i32 %i, -1
+ %r = select i1 %ispos, float 2.0, float -1.0
+ ret float %r
+}
More information about the llvm-commits
mailing list