[llvm] 5683801 - [InstCombine] add tests for reassociative fadd with negated op; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 11 09:03:52 PDT 2022
Author: Sanjay Patel
Date: 2022-08-11T11:43:36-04:00
New Revision: 5683801c561a5032f5eef2b3c90e551ad9a85d3e
URL: https://github.com/llvm/llvm-project/commit/5683801c561a5032f5eef2b3c90e551ad9a85d3e
DIFF: https://github.com/llvm/llvm-project/commit/5683801c561a5032f5eef2b3c90e551ad9a85d3e.diff
LOG: [InstCombine] add tests for reassociative fadd with negated op; NFC
Extra uses inhibit more basic folds, so we miss the larger fold.
Added:
Modified:
llvm/test/Transforms/InstCombine/fadd.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/fadd.ll b/llvm/test/Transforms/InstCombine/fadd.ll
index 47b65c313d93..275cecd35423 100644
--- a/llvm/test/Transforms/InstCombine/fadd.ll
+++ b/llvm/test/Transforms/InstCombine/fadd.ll
@@ -527,3 +527,96 @@ define float @fadd_fmul_common_op_wrong_fmf(float %x) {
%a = fadd ninf nsz float %m, %x
ret float %a
}
+
+; (-x - y) + (x + z) --> z - y
+
+define float @fadd_fneg_reass_commute0(float %x, float %y, float %z) {
+; CHECK-LABEL: @fadd_fneg_reass_commute0(
+; CHECK-NEXT: [[N:%.*]] = fneg reassoc nsz float [[X:%.*]]
+; CHECK-NEXT: call void @use(float [[N]])
+; CHECK-NEXT: [[S:%.*]] = fsub reassoc nsz float [[N]], [[Y:%.*]]
+; CHECK-NEXT: [[A:%.*]] = fadd reassoc nsz float [[X]], [[Z:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[S]], [[A]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %n = fneg reassoc nsz float %x
+ call void @use(float %n)
+ %s = fsub reassoc nsz float %n, %y
+ %a = fadd reassoc nsz float %x, %z
+ %r = fadd reassoc nsz float %s, %a
+ ret float %r
+}
+
+define float @fadd_fneg_reass_commute1(float %x, float %y, float %z) {
+; CHECK-LABEL: @fadd_fneg_reass_commute1(
+; CHECK-NEXT: [[N:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT: call void @use(float [[N]])
+; CHECK-NEXT: [[S:%.*]] = fsub float [[N]], [[Y:%.*]]
+; CHECK-NEXT: call void @use(float [[S]])
+; CHECK-NEXT: [[A:%.*]] = fadd float [[X]], [[Z:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz float [[A]], [[S]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %n = fneg float %x
+ call void @use(float %n)
+ %s = fsub float %n, %y
+ call void @use(float %s)
+ %a = fadd float %x, %z
+ %r = fadd reassoc nsz float %a, %s
+ ret float %r
+}
+
+define float @fadd_fneg_reass_commute2(float %x, float %y, float %z) {
+; CHECK-LABEL: @fadd_fneg_reass_commute2(
+; CHECK-NEXT: [[N:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT: call void @use(float [[N]])
+; CHECK-NEXT: [[S:%.*]] = fsub float [[N]], [[Y:%.*]]
+; CHECK-NEXT: call void @use(float [[S]])
+; CHECK-NEXT: [[A:%.*]] = fadd float [[Z:%.*]], [[X]]
+; CHECK-NEXT: call void @use(float [[A]])
+; CHECK-NEXT: [[R:%.*]] = fadd fast float [[S]], [[A]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %n = fneg float %x
+ call void @use(float %n)
+ %s = fsub float %n, %y
+ call void @use(float %s)
+ %a = fadd float %z, %x
+ call void @use(float %a)
+ %r = fadd fast float %s, %a
+ ret float %r
+}
+
+define <2 x float> @fadd_fneg_reass_commute3(<2 x float> %x, <2 x float> %y, <2 x float> %z) {
+; CHECK-LABEL: @fadd_fneg_reass_commute3(
+; CHECK-NEXT: [[N:%.*]] = fneg reassoc nsz <2 x float> [[X:%.*]]
+; CHECK-NEXT: call void @use_vec(<2 x float> [[N]])
+; CHECK-NEXT: [[S:%.*]] = fsub reassoc nsz <2 x float> [[N]], [[Y:%.*]]
+; CHECK-NEXT: [[A:%.*]] = fadd reassoc nsz <2 x float> [[Z:%.*]], [[X]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz <2 x float> [[A]], [[S]]
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %n = fneg reassoc nsz <2 x float> %x
+ call void @use_vec(<2 x float> %n)
+ %s = fsub reassoc nsz <2 x float> %n, %y
+ %a = fadd reassoc nsz <2 x float> %z, %x
+ %r = fadd reassoc nsz <2 x float> %a, %s
+ ret <2 x float> %r
+}
+
+define float @fadd_fneg_commute0(float %x, float %y, float %z) {
+; CHECK-LABEL: @fadd_fneg_commute0(
+; CHECK-NEXT: [[N:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT: call void @use(float [[N]])
+; CHECK-NEXT: [[S:%.*]] = fsub float [[N]], [[Y:%.*]]
+; CHECK-NEXT: [[A:%.*]] = fadd float [[X]], [[Z:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fadd nsz float [[S]], [[A]]
+; CHECK-NEXT: ret float [[R]]
+;
+ %n = fneg float %x
+ call void @use(float %n)
+ %s = fsub float %n, %y
+ %a = fadd float %x, %z
+ %r = fadd nsz float %s, %a
+ ret float %r
+}
More information about the llvm-commits
mailing list