[llvm] [InstCombine] Clear sign-bit of the constant magnitude in copysign (PR #85787)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 06:57:32 PDT 2024
================
@@ -275,6 +275,52 @@ define half @fneg_fabs_copysign_multi_use_fabs(half %x, half %y, ptr %ptr) {
ret half %fabs.copysign
}
+define half @copysign_pos(half %a) {
+; CHECK-LABEL: @copysign_pos(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RET:%.*]] = call half @llvm.copysign.f16(half 0xH3C00, half [[A:%.*]])
+; CHECK-NEXT: ret half [[RET]]
+;
+entry:
+ %ret = call half @llvm.copysign.f16(half 0xH3C00, half %a)
+ ret half %ret
+}
+
+define half @copysign_neg(half %a) {
+; CHECK-LABEL: @copysign_neg(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RET:%.*]] = call half @llvm.copysign.f16(half 0xH3C00, half [[A:%.*]])
+; CHECK-NEXT: ret half [[RET]]
+;
+entry:
+ %ret = call half @llvm.copysign.f16(half 0xHBC00, half %a)
+ ret half %ret
+}
+
+define <4 x half> @copysign_splat(<4 x half> %a) {
+; CHECK-LABEL: @copysign_splat(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RET:%.*]] = call <4 x half> @llvm.copysign.v4f16(<4 x half> <half 0xH3C00, half 0xH3C00, half 0xH3C00, half 0xH3C00>, <4 x half> [[A:%.*]])
+; CHECK-NEXT: ret <4 x half> [[RET]]
+;
+entry:
+ %ret = call <4 x half> @llvm.copysign.v4f16(<4 x half> splat(half 0xHBC00), <4 x half> %a)
+ ret <4 x half> %ret
+}
+
+; TODO: Support constant folding of fabs
+
+define <4 x half> @copysign_vec4(<4 x half> %a) {
+; CHECK-LABEL: @copysign_vec4(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RET:%.*]] = call <4 x half> @llvm.copysign.v4f16(<4 x half> <half 0xH3C00, half 0xHBC00, half undef, half poison>, <4 x half> [[A:%.*]])
+; CHECK-NEXT: ret <4 x half> [[RET]]
+;
+entry:
+ %ret = call <4 x half> @llvm.copysign.v4f16(<4 x half> <half 0xH3C00, half 0xHBC00, half undef, half poison>, <4 x half> %a)
+ ret <4 x half> %ret
+}
+
----------------
arsenm wrote:
Maybe test 0 and nan cases
https://github.com/llvm/llvm-project/pull/85787
More information about the llvm-commits
mailing list