[llvm] fc3cf48 - [InstCombine] add tests for fmul/fdiv with fabs operands; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 20 08:47:48 PDT 2020
Author: Sanjay Patel
Date: 2020-06-20T11:44:27-04:00
New Revision: fc3cf48e1268702ee97a0f67a92976c9bec42a75
URL: https://github.com/llvm/llvm-project/commit/fc3cf48e1268702ee97a0f67a92976c9bec42a75
DIFF: https://github.com/llvm/llvm-project/commit/fc3cf48e1268702ee97a0f67a92976c9bec42a75.diff
LOG: [InstCombine] add tests for fmul/fdiv with fabs operands; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/fdiv.ll
llvm/test/Transforms/InstCombine/fmul.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/fdiv.ll b/llvm/test/Transforms/InstCombine/fdiv.ll
index ce9548f29a29..deceb724007e 100644
--- a/llvm/test/Transforms/InstCombine/fdiv.ll
+++ b/llvm/test/Transforms/InstCombine/fdiv.ll
@@ -595,3 +595,63 @@ define float @fabs_same_op_extra_use(float %x) {
%r = fdiv ninf reassoc float %a, %a
ret float %r
}
+
+define float @fabs_fabs(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs(
+; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fdiv float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %x.fabs = call float @llvm.fabs.f32(float %x)
+ %y.fabs = call float @llvm.fabs.f32(float %y)
+ %r = fdiv float %x.fabs, %y.fabs
+ ret float %r
+}
+
+define float @fabs_fabs_extra_use1(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs_extra_use1(
+; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[X_FABS]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fdiv ninf float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %x.fabs = call float @llvm.fabs.f32(float %x)
+ call void @use_f32(float %x.fabs)
+ %y.fabs = call float @llvm.fabs.f32(float %y)
+ %r = fdiv ninf float %x.fabs, %y.fabs
+ ret float %r
+}
+
+define float @fabs_fabs_extra_use2(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs_extra_use2(
+; CHECK-NEXT: [[X_FABS:%.*]] = call fast float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call fast float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[Y_FABS]])
+; CHECK-NEXT: [[R:%.*]] = fdiv reassoc ninf float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %x.fabs = call fast float @llvm.fabs.f32(float %x)
+ %y.fabs = call fast float @llvm.fabs.f32(float %y)
+ call void @use_f32(float %y.fabs)
+ %r = fdiv reassoc ninf float %x.fabs, %y.fabs
+ ret float %r
+}
+
+define float @fabs_fabs_extra_use3(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs_extra_use3(
+; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[X_FABS]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[Y_FABS]])
+; CHECK-NEXT: [[R:%.*]] = fdiv float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %x.fabs = call float @llvm.fabs.f32(float %x)
+ call void @use_f32(float %x.fabs)
+ %y.fabs = call float @llvm.fabs.f32(float %y)
+ call void @use_f32(float %y.fabs)
+ %r = fdiv float %x.fabs, %y.fabs
+ ret float %r
+}
diff --git a/llvm/test/Transforms/InstCombine/fmul.ll b/llvm/test/Transforms/InstCombine/fmul.ll
index 350cc90f6834..0559a7907de0 100644
--- a/llvm/test/Transforms/InstCombine/fmul.ll
+++ b/llvm/test/Transforms/InstCombine/fmul.ll
@@ -480,8 +480,8 @@ define float @fabs_squared_fast(float %x) {
ret float %mul
}
-define float @fabs_x_fabs(float %x, float %y) {
-; CHECK-LABEL: @fabs_x_fabs(
+define float @fabs_fabs(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs(
; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X_FABS]], [[Y_FABS]]
@@ -493,6 +493,53 @@ define float @fabs_x_fabs(float %x, float %y) {
ret float %mul
}
+define float @fabs_fabs_extra_use1(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs_extra_use1(
+; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[X_FABS]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[MUL:%.*]] = fmul ninf float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[MUL]]
+;
+ %x.fabs = call float @llvm.fabs.f32(float %x)
+ call void @use_f32(float %x.fabs)
+ %y.fabs = call float @llvm.fabs.f32(float %y)
+ %mul = fmul ninf float %x.fabs, %y.fabs
+ ret float %mul
+}
+
+define float @fabs_fabs_extra_use2(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs_extra_use2(
+; CHECK-NEXT: [[X_FABS:%.*]] = call fast float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call fast float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[Y_FABS]])
+; CHECK-NEXT: [[MUL:%.*]] = fmul reassoc ninf float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[MUL]]
+;
+ %x.fabs = call fast float @llvm.fabs.f32(float %x)
+ %y.fabs = call fast float @llvm.fabs.f32(float %y)
+ call void @use_f32(float %y.fabs)
+ %mul = fmul reassoc ninf float %x.fabs, %y.fabs
+ ret float %mul
+}
+
+define float @fabs_fabs_extra_use3(float %x, float %y) {
+; CHECK-LABEL: @fabs_fabs_extra_use3(
+; CHECK-NEXT: [[X_FABS:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[X_FABS]])
+; CHECK-NEXT: [[Y_FABS:%.*]] = call float @llvm.fabs.f32(float [[Y:%.*]])
+; CHECK-NEXT: call void @use_f32(float [[Y_FABS]])
+; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X_FABS]], [[Y_FABS]]
+; CHECK-NEXT: ret float [[MUL]]
+;
+ %x.fabs = call float @llvm.fabs.f32(float %x)
+ call void @use_f32(float %x.fabs)
+ %y.fabs = call float @llvm.fabs.f32(float %y)
+ call void @use_f32(float %y.fabs)
+ %mul = fmul float %x.fabs, %y.fabs
+ ret float %mul
+}
+
; (X*Y) * X => (X*X) * Y
; The transform only requires 'reassoc', but test other FMF in
; the commuted variants to make sure FMF propagates as expected.
@@ -572,9 +619,9 @@ declare float @llvm.log2.f32(float)
define float @log2half(float %x, float %y) {
; CHECK-LABEL: @log2half(
-; CHECK-NEXT: [[LOG2:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
-; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[LOG2]], [[X:%.*]]
-; CHECK-NEXT: [[MUL:%.*]] = fsub fast float [[TMP1]], [[X]]
+; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[X:%.*]]
+; CHECK-NEXT: [[MUL:%.*]] = fsub fast float [[TMP2]], [[X]]
; CHECK-NEXT: ret float [[MUL]]
;
%halfy = fmul float %y, 0.5
@@ -585,10 +632,10 @@ define float @log2half(float %x, float %y) {
define float @log2half_commute(float %x1, float %y) {
; CHECK-LABEL: @log2half_commute(
-; CHECK-NEXT: [[LOG2:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
-; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float [[LOG2]], [[X1:%.*]]
-; CHECK-NEXT: [[TMP2:%.*]] = fsub fast float [[TMP1]], [[X1]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[TMP2]], 0x3FC24924A0000000
+; CHECK-NEXT: [[TMP1:%.*]] = call fast float @llvm.log2.f32(float [[Y:%.*]])
+; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[X1:%.*]]
+; CHECK-NEXT: [[TMP3:%.*]] = fsub fast float [[TMP2]], [[X1]]
+; CHECK-NEXT: [[MUL:%.*]] = fmul fast float [[TMP3]], 0x3FC24924A0000000
; CHECK-NEXT: ret float [[MUL]]
;
%x = fdiv float %x1, 7.0 ; thwart complexity-based canonicalization
More information about the llvm-commits
mailing list