[llvm] r339470 - [InstCombine] add tests for fsub factorization; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 10 14:00:28 PDT 2018
Author: spatel
Date: Fri Aug 10 14:00:27 2018
New Revision: 339470
URL: http://llvm.org/viewvc/llvm-project?rev=339470&view=rev
Log:
[InstCombine] add tests for fsub factorization; NFC
The tests show that;
1. The fold doesn't fire for vectors, but it should.
2. The fold fires regardless of uses, but it shouldn't.
Modified:
llvm/trunk/test/Transforms/InstCombine/fast-math.ll
Modified: llvm/trunk/test/Transforms/InstCombine/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fast-math.ll?rev=339470&r1=339469&r2=339470&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fast-math.ll Fri Aug 10 14:00:27 2018
@@ -748,25 +748,99 @@ define float @fact_mul3_reassoc(float %x
; x*z - z*y => (x-y) * z
define float @fact_mul4(float %x, float %y, float %z) {
; CHECK-LABEL: @fact_mul4(
-; CHECK-NEXT: [[TMP1:%.*]] = fsub fast float [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[TMP2:%.*]] = fmul fast float [[TMP1]], [[Z:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], [[Z:%.*]]
; CHECK-NEXT: ret float [[TMP2]]
;
- %t1 = fmul fast float %x, %z
- %t2 = fmul fast float %z, %y
- %t3 = fsub fast float %t1, %t2
+ %t1 = fmul float %x, %z
+ %t2 = fmul float %z, %y
+ %t3 = fsub reassoc nsz float %t1, %t2
ret float %t3
}
-; Check again using the minimal subset of FMF.
-define float @fact_mul4_reassoc_nsz(float %x, float %y, float %z) {
-; CHECK-LABEL: @fact_mul4_reassoc_nsz(
+define float @fact_mul4_commute1(float %x, float %y, float %z) {
+; CHECK-LABEL: @fact_mul4_commute1(
; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], [[Z:%.*]]
; CHECK-NEXT: ret float [[TMP2]]
;
- %t1 = fmul reassoc nsz float %x, %z
- %t2 = fmul reassoc nsz float %z, %y
+ %t1 = fmul float %x, %z
+ %t2 = fmul float %y, %z
+ %t3 = fsub reassoc nsz float %t1, %t2
+ ret float %t3
+}
+
+define float @fact_mul4_commute2(float %x, float %y, float %z) {
+; CHECK-LABEL: @fact_mul4_commute2(
+; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], [[Z:%.*]]
+; CHECK-NEXT: ret float [[TMP2]]
+;
+ %t1 = fmul float %z, %x
+ %t2 = fmul float %y, %z
+ %t3 = fsub reassoc nsz float %t1, %t2
+ ret float %t3
+}
+
+define <2 x float> @fact_mul4_commute3_vec(<2 x float> %x, <2 x float> %y, <2 x float> %z) {
+; CHECK-LABEL: @fact_mul4_commute3_vec(
+; CHECK-NEXT: [[T1:%.*]] = fmul <2 x float> [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: [[T2:%.*]] = fmul <2 x float> [[Z]], [[Y:%.*]]
+; CHECK-NEXT: [[T3:%.*]] = fsub reassoc nsz <2 x float> [[T1]], [[T2]]
+; CHECK-NEXT: ret <2 x float> [[T3]]
+;
+ %t1 = fmul <2 x float> %z, %x
+ %t2 = fmul <2 x float> %z, %y
+ %t3 = fsub reassoc nsz <2 x float> %t1, %t2
+ ret <2 x float> %t3
+}
+
+declare void @use(float)
+
+define float @fact_mul4_uses1(float %x, float %y, float %z) {
+; CHECK-LABEL: @fact_mul4_uses1(
+; CHECK-NEXT: [[T1:%.*]] = fmul float [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: call void @use(float [[T1]])
+; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], [[Z]]
+; CHECK-NEXT: ret float [[TMP2]]
+;
+ %t1 = fmul float %z, %x
+ call void @use(float %t1)
+ %t2 = fmul float %y, %z
+ %t3 = fsub reassoc nsz float %t1, %t2
+ ret float %t3
+}
+
+define float @fact_mul4_uses2(float %x, float %y, float %z) {
+; CHECK-LABEL: @fact_mul4_uses2(
+; CHECK-NEXT: [[T2:%.*]] = fmul float [[Y:%.*]], [[Z:%.*]]
+; CHECK-NEXT: call void @use(float [[T2]])
+; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X:%.*]], [[Y]]
+; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], [[Z]]
+; CHECK-NEXT: ret float [[TMP2]]
+;
+ %t1 = fmul float %x, %z
+ %t2 = fmul float %y, %z
+ call void @use(float %t2)
+ %t3 = fsub reassoc nsz float %t1, %t2
+ ret float %t3
+}
+
+define float @fact_mul4_uses3(float %x, float %y, float %z) {
+; CHECK-LABEL: @fact_mul4_uses3(
+; CHECK-NEXT: [[T1:%.*]] = fmul float [[Z:%.*]], [[X:%.*]]
+; CHECK-NEXT: call void @use(float [[T1]])
+; CHECK-NEXT: [[T2:%.*]] = fmul float [[Z]], [[Y:%.*]]
+; CHECK-NEXT: call void @use(float [[T2]])
+; CHECK-NEXT: [[TMP1:%.*]] = fsub reassoc nsz float [[X]], [[Y]]
+; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz float [[TMP1]], [[Z]]
+; CHECK-NEXT: ret float [[TMP2]]
+;
+ %t1 = fmul float %z, %x
+ call void @use(float %t1)
+ %t2 = fmul float %z, %y
+ call void @use(float %t2)
%t3 = fsub reassoc nsz float %t1, %t2
ret float %t3
}
More information about the llvm-commits
mailing list