llvm.org GIT mirror llvm / d841b7b
[Constants] add identity constants for fadd/fmul As the test diffs show, the current users of getBinOpIdentity() are InstCombine and Reassociate. SLP vectorizer is a candidate for using this functionality too (D28907). The InstCombine shuffle improvements are part of the planned enhancements noted in D48830. InstCombine actually has several other uses of getBinOpIdentity() via SimplifyUsingDistributiveLaws(), but we don't call that for any FP ops. Fixing that might be another part of removing the custom reassociation in InstCombine that is only done for fadd+fmul. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336215 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 1 year, 2 months ago
4 changed file(s) with 15 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
22802280 case Instruction::And:
22812281 return Constant::getAllOnesValue(Ty);
22822282
2283 // FIXME: FAdd / FMul?
2283 // TODO: If the fadd has 'nsz', should we return +0.0?
2284 case Instruction::FAdd:
2285 return ConstantFP::getNegativeZero(Ty);
2286
2287 case Instruction::FMul:
2288 return ConstantFP::get(Ty, 1.0);
22842289 }
22852290 }
22862291
162162
163163 define <4 x float> @fadd(<4 x float> %v) {
164164 ; CHECK-LABEL: @fadd(
165 ; CHECK-NEXT: [[B:%.*]] = fadd <4 x float> [[V:%.*]],
166 ; CHECK-NEXT: [[S:%.*]] = shufflevector <4 x float> [[B]], <4 x float> [[V]], <4 x i32> >
165 ; CHECK-NEXT: [[S:%.*]] = fadd <4 x float> [[V:%.*]], >
167166 ; CHECK-NEXT: ret <4 x float> [[S]]
168167 ;
169168 %b = fadd <4 x float> %v,
186185
187186 define <4 x float> @fmul(<4 x float> %v) {
188187 ; CHECK-LABEL: @fmul(
189 ; CHECK-NEXT: [[B:%.*]] = fmul nnan ninf <4 x float> [[V:%.*]],
190 ; CHECK-NEXT: [[S:%.*]] = shufflevector <4 x float> [[B]], <4 x float> [[V]], <4 x i32> >
188 ; CHECK-NEXT: [[S:%.*]] = fmul nnan ninf <4 x float> [[V:%.*]], >
191189 ; CHECK-NEXT: ret <4 x float> [[S]]
192190 ;
193191 %b = fmul nnan ninf <4 x float> %v,
4747 ret i8 %a2
4848 }
4949
50 ; FIXME
50 ; FIXME - the binop identity constant for fadd is -0.0, so this didn't fold.
5151
5252 define float @fadd_0(float %x) {
5353 ; CHECK-LABEL: @fadd_0(
5959 ret float %a2
6060 }
6161
62 ; FIXME
63
6462 define float @fmul_1(float %x) {
6563 ; CHECK-LABEL: @fmul_1(
66 ; CHECK-NEXT: [[A2:%.*]] = fmul fast float [[X:%.*]], 1.000000e+00
67 ; CHECK-NEXT: ret float [[A2]]
64 ; CHECK-NEXT: ret float [[X:%.*]]
6865 ;
6966 %a1 = fmul fast float %x, 4.0
7067 %a2 = fmul fast float %a1, 0.25
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -reassociate -S | FileCheck %s
12
23 ; Input is A op (B op C)
34
45 define half @faddsubAssoc1(half %a, half %b) {
56 ; CHECK-LABEL: @faddsubAssoc1(
6 ; CHECK-NEXT: [[T2_NEG:%.*]] = fmul fast half %a, 0xH4500
7 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast half %b, 0xH4500
7 ; CHECK-NEXT: [[T2_NEG:%.*]] = fmul fast half [[A:%.*]], 0xH4500
8 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast half [[B:%.*]], 0xH4500
89 ; CHECK-NEXT: [[T51:%.*]] = fsub fast half [[REASS_MUL]], [[T2_NEG]]
910 ; CHECK-NEXT: [[T5:%.*]] = fadd fast half [[REASS_MUL]], [[T2_NEG]]
1011 ; CHECK-NEXT: ret half [[T51]]
2122
2223 define half @faddsubAssoc2(half %a, half %b) {
2324 ; CHECK-LABEL: @faddsubAssoc2(
24 ; CHECK-NEXT: [[T2:%.*]] = fmul fast half %a, 0xH4500
25 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast half %b, 0xH3C00
26 ; CHECK-NEXT: [[T5:%.*]] = fadd fast half [[REASS_MUL]], [[T2]]
25 ; CHECK-NEXT: [[T2:%.*]] = fmul fast half [[A:%.*]], 0xH4500
26 ; CHECK-NEXT: [[T5:%.*]] = fadd fast half [[B:%.*]], [[T2]]
2727 ; CHECK-NEXT: ret half [[T5]]
2828 ;
2929 %t1 = fmul fast half %b, 0xH4200 ; 3*b