Skip to content

Commit ddd1127

Browse files
author
Simon Moll
committed
Remove BinaryOperator::CreateFNeg
Use UnaryOperator::CreateFNeg instead. Summary: With the introduction of the native fneg instruction, the fsub -0.0, %x idiom is obsolete. This patch makes LLVM emit fneg instead of the idiom in all places. Reviewed By: cameron.mcinally Differential Revision: https://reviews.llvm.org/D75130
1 parent 740ed61 commit ddd1127

23 files changed

+87
-108
lines changed

clang/test/CodeGen/complex-math.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ float _Complex div_float_rc(float a, float _Complex b) {
149149
// AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast float [[CC]], [[DD]]
150150
//
151151
// BC = 0
152-
// AARCH64-FASTMATH: [[NEGA:%.*]] = fsub fast float -0.000000e+00, %a
152+
// AARCH64-FASTMATH: [[NEGA:%.*]] = fneg fast float %a
153153
// AARCH64-FASTMATH: [[AD:%.*]] = fmul fast float [[D]], [[NEGA]]
154154
//
155155
// AARCH64-FASTMATH: fdiv fast float [[AC]], [[CCpDD]]
@@ -327,7 +327,7 @@ double _Complex div_double_rc(double a, double _Complex b) {
327327
// AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast double [[CC]], [[DD]]
328328
//
329329
// BC = 0
330-
// AARCH64-FASTMATH: [[NEGA:%.*]] = fsub fast double -0.000000e+00, %a
330+
// AARCH64-FASTMATH: [[NEGA:%.*]] = fneg fast double %a
331331
// AARCH64-FASTMATH: [[AD:%.*]] = fmul fast double [[D]], [[NEGA]]
332332
//
333333
// AARCH64-FASTMATH: fdiv fast double [[AC]], [[CCpDD]]
@@ -523,7 +523,7 @@ long double _Complex div_long_double_rc(long double a, long double _Complex b) {
523523
// AARCH64-FASTMATH: [[CCpDD:%.*]] = fadd fast fp128 [[CC]], [[DD]]
524524
//
525525
// BC = 0
526-
// AARCH64-FASTMATH: [[NEGA:%.*]] = fsub fast fp128 0xL00000000000000008000000000000000, %a
526+
// AARCH64-FASTMATH: [[NEGA:%.*]] = fneg fast fp128 %a
527527
// AARCH64-FASTMATH: [[AD:%.*]] = fmul fast fp128 [[D]], [[NEGA]]
528528
//
529529
// AARCH64-FASTMATH: fdiv fast fp128 [[AC]], [[CCpDD]]

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,20 @@ class UnaryOperator : public UnaryInstruction {
154154
}
155155
#include "llvm/IR/Instruction.def"
156156

157-
static UnaryOperator *CreateWithCopiedFlags(UnaryOps Opc,
158-
Value *V,
159-
Instruction *CopyO,
160-
const Twine &Name = "") {
161-
UnaryOperator *UO = Create(Opc, V, Name);
157+
static UnaryOperator *
158+
CreateWithCopiedFlags(UnaryOps Opc, Value *V, Instruction *CopyO,
159+
const Twine &Name = "",
160+
Instruction *InsertBefore = nullptr) {
161+
UnaryOperator *UO = Create(Opc, V, Name, InsertBefore);
162162
UO->copyIRFlags(CopyO);
163163
return UO;
164164
}
165165

166166
static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
167-
const Twine &Name = "") {
168-
return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name);
167+
const Twine &Name = "",
168+
Instruction *InsertBefore = nullptr) {
169+
return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name,
170+
InsertBefore);
169171
}
170172

171173
UnaryOps getOpcode() const {
@@ -280,11 +282,6 @@ class BinaryOperator : public Instruction {
280282
const Twine &Name = "") {
281283
return CreateWithCopiedFlags(Instruction::FRem, V1, V2, FMFSource, Name);
282284
}
283-
static BinaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
284-
const Twine &Name = "") {
285-
Value *Zero = ConstantFP::getNegativeZero(Op->getType());
286-
return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource, Name);
287-
}
288285

289286
static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
290287
const Twine &Name = "") {
@@ -390,10 +387,6 @@ class BinaryOperator : public Instruction {
390387
Instruction *InsertBefore = nullptr);
391388
static BinaryOperator *CreateNUWNeg(Value *Op, const Twine &Name,
392389
BasicBlock *InsertAtEnd);
393-
static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name = "",
394-
Instruction *InsertBefore = nullptr);
395-
static BinaryOperator *CreateFNeg(Value *Op, const Twine &Name,
396-
BasicBlock *InsertAtEnd);
397390
static BinaryOperator *CreateNot(Value *Op, const Twine &Name = "",
398391
Instruction *InsertBefore = nullptr);
399392
static BinaryOperator *CreateNot(Value *Op, const Twine &Name,

llvm/lib/IR/Instructions.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,20 +2393,6 @@ BinaryOperator *BinaryOperator::CreateNUWNeg(Value *Op, const Twine &Name,
23932393
return BinaryOperator::CreateNUWSub(zero, Op, Name, InsertAtEnd);
23942394
}
23952395

2396-
BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name,
2397-
Instruction *InsertBefore) {
2398-
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2399-
return new BinaryOperator(Instruction::FSub, zero, Op,
2400-
Op->getType(), Name, InsertBefore);
2401-
}
2402-
2403-
BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name,
2404-
BasicBlock *InsertAtEnd) {
2405-
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
2406-
return new BinaryOperator(Instruction::FSub, zero, Op,
2407-
Op->getType(), Name, InsertAtEnd);
2408-
}
2409-
24102396
BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
24112397
Instruction *InsertBefore) {
24122398
Constant *C = Constant::getAllOnesValue(Op->getType());

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
21362136
// fsub nsz 0, X ==> fsub nsz -0.0, X
21372137
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
21382138
if (I.hasNoSignedZeros() && match(Op0, m_PosZeroFP()))
2139-
return BinaryOperator::CreateFNegFMF(Op1, &I);
2139+
return UnaryOperator::CreateFNegFMF(Op1, &I);
21402140

21412141
if (Instruction *X = foldFNegIntoConstant(I))
21422142
return X;
@@ -2214,12 +2214,12 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
22142214
if (I.hasAllowReassoc() && I.hasNoSignedZeros()) {
22152215
// (Y - X) - Y --> -X
22162216
if (match(Op0, m_FSub(m_Specific(Op1), m_Value(X))))
2217-
return BinaryOperator::CreateFNegFMF(X, &I);
2217+
return UnaryOperator::CreateFNegFMF(X, &I);
22182218

22192219
// Y - (X + Y) --> -X
22202220
// Y - (Y + X) --> -X
22212221
if (match(Op1, m_c_FAdd(m_Specific(Op0), m_Value(X))))
2222-
return BinaryOperator::CreateFNegFMF(X, &I);
2222+
return UnaryOperator::CreateFNegFMF(X, &I);
22232223

22242224
// (X * C) - X --> X * (C - 1.0)
22252225
if (match(Op0, m_FMul(m_Specific(Op1), m_Constant(C)))) {

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
21892189
llvm_unreachable("unexpected intrinsic ID");
21902190
}
21912191
Value *NewCall = Builder.CreateBinaryIntrinsic(NewIID, X, Y, II);
2192-
Instruction *FNeg = BinaryOperator::CreateFNeg(NewCall);
2192+
Instruction *FNeg = UnaryOperator::CreateFNeg(NewCall);
21932193
FNeg->copyIRFlags(II);
21942194
return FNeg;
21952195
}
@@ -2354,7 +2354,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
23542354
if (match(II->getArgOperand(0), m_OneUse(m_FNeg(m_Value(X))))) {
23552355
// sin(-x) --> -sin(x)
23562356
Value *NewSin = Builder.CreateUnaryIntrinsic(Intrinsic::sin, X, II);
2357-
Instruction *FNeg = BinaryOperator::CreateFNeg(NewSin);
2357+
Instruction *FNeg = UnaryOperator::CreateFNeg(NewSin);
23582358
FNeg->copyFastMathFlags(II);
23592359
return FNeg;
23602360
}

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &FPT) {
16391639
// FIXME: Once we're sure that unary FNeg optimizations are on par with
16401640
// binary FNeg, this should always return a unary operator.
16411641
if (isa<BinaryOperator>(Op))
1642-
return BinaryOperator::CreateFNegFMF(InnerTrunc, Op);
1642+
return UnaryOperator::CreateFNegFMF(InnerTrunc, Op);
16431643
return UnaryOperator::CreateFNegFMF(InnerTrunc, Op);
16441644
}
16451645

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
411411
// X * -1.0 --> -X
412412
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
413413
if (match(Op1, m_SpecificFP(-1.0)))
414-
return BinaryOperator::CreateFNegFMF(Op0, &I);
414+
return UnaryOperator::CreateFNegFMF(Op0, &I);
415415

416416
// -X * -Y --> X * Y
417417
Value *X, *Y;

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Instruction *InstCombiner::foldSelectOpOp(SelectInst &SI, Instruction *TI,
341341
// TODO: Remove the hack for the binop form when the unary op is optimized
342342
// properly with all IR passes.
343343
if (TI->getOpcode() != Instruction::FNeg)
344-
return BinaryOperator::CreateFNegFMF(NewSel, cast<BinaryOperator>(TI));
344+
return UnaryOperator::CreateFNegFMF(NewSel, cast<BinaryOperator>(TI));
345345
return UnaryOperator::CreateFNeg(NewSel);
346346
}
347347

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ static BinaryOperator *CreateMul(Value *S1, Value *S2, const Twine &Name,
254254
}
255255
}
256256

257-
static BinaryOperator *CreateNeg(Value *S1, const Twine &Name,
258-
Instruction *InsertBefore, Value *FlagsOp) {
257+
static Instruction *CreateNeg(Value *S1, const Twine &Name,
258+
Instruction *InsertBefore, Value *FlagsOp) {
259259
if (S1->getType()->isIntOrIntVectorTy())
260260
return BinaryOperator::CreateNeg(S1, Name, InsertBefore);
261-
else {
262-
BinaryOperator *Res = BinaryOperator::CreateFNeg(S1, Name, InsertBefore);
263-
Res->setFastMathFlags(cast<FPMathOperator>(FlagsOp)->getFastMathFlags());
264-
return Res;
265-
}
261+
262+
if (auto *FMFSource = dyn_cast<Instruction>(FlagsOp))
263+
return UnaryOperator::CreateFNegFMF(S1, FMFSource, Name, InsertBefore);
264+
265+
return UnaryOperator::CreateFNeg(S1, Name, InsertBefore);
266266
}
267267

268268
/// Replace 0-X with X*-1.
@@ -914,7 +914,7 @@ static Value *NegateValue(Value *V, Instruction *BI,
914914

915915
// Insert a 'neg' instruction that subtracts the value from zero to get the
916916
// negation.
917-
BinaryOperator *NewNeg = CreateNeg(V, V->getName() + ".neg", BI, BI);
917+
Instruction *NewNeg = CreateNeg(V, V->getName() + ".neg", BI, BI);
918918
ToRedo.insert(NewNeg);
919919
return NewNeg;
920920
}

llvm/test/Transforms/InstCombine/cos-sin-intrinsic.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ declare <2 x float> @llvm.sin.v2f32(<2 x float>)
151151
define <2 x float> @fneg_sin(<2 x float> %x){
152152
; CHECK-LABEL: @fneg_sin(
153153
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
154-
; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
154+
; CHECK-NEXT: [[R:%.*]] = fneg <2 x float> [[TMP1]]
155155
; CHECK-NEXT: ret <2 x float> [[R]]
156156
;
157157
%negx = fsub <2 x float> <float -0.0, float -0.0>, %x
@@ -162,7 +162,7 @@ define <2 x float> @fneg_sin(<2 x float> %x){
162162
define <2 x float> @unary_fneg_sin(<2 x float> %x){
163163
; CHECK-LABEL: @unary_fneg_sin(
164164
; CHECK-NEXT: [[TMP1:%.*]] = call <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
165-
; CHECK-NEXT: [[R:%.*]] = fsub <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
165+
; CHECK-NEXT: [[R:%.*]] = fneg <2 x float> [[TMP1]]
166166
; CHECK-NEXT: ret <2 x float> [[R]]
167167
;
168168
%negx = fneg <2 x float> %x
@@ -175,7 +175,7 @@ define <2 x float> @unary_fneg_sin(<2 x float> %x){
175175
define <2 x float> @fneg_sin_fmf(<2 x float> %x){
176176
; CHECK-LABEL: @fneg_sin_fmf(
177177
; CHECK-NEXT: [[TMP1:%.*]] = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
178-
; CHECK-NEXT: [[R:%.*]] = fsub nnan arcp afn <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
178+
; CHECK-NEXT: [[R:%.*]] = fneg nnan arcp afn <2 x float> [[TMP1]]
179179
; CHECK-NEXT: ret <2 x float> [[R]]
180180
;
181181
%negx = fsub fast <2 x float> <float -0.0, float -0.0>, %x
@@ -186,7 +186,7 @@ define <2 x float> @fneg_sin_fmf(<2 x float> %x){
186186
define <2 x float> @unary_fneg_sin_fmf(<2 x float> %x){
187187
; CHECK-LABEL: @unary_fneg_sin_fmf(
188188
; CHECK-NEXT: [[TMP1:%.*]] = call nnan arcp afn <2 x float> @llvm.sin.v2f32(<2 x float> [[X:%.*]])
189-
; CHECK-NEXT: [[R:%.*]] = fsub nnan arcp afn <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[TMP1]]
189+
; CHECK-NEXT: [[R:%.*]] = fneg nnan arcp afn <2 x float> [[TMP1]]
190190
; CHECK-NEXT: ret <2 x float> [[R]]
191191
;
192192
%negx = fneg fast <2 x float> %x

llvm/test/Transforms/InstCombine/fast-math.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ define float @fold8_reassoc(float %f1) {
269269

270270
define float @fsub_fadd_common_op_fneg(float %x, float %y) {
271271
; CHECK-LABEL: @fsub_fadd_common_op_fneg(
272-
; CHECK-NEXT: [[R:%.*]] = fsub fast float -0.000000e+00, [[X:%.*]]
272+
; CHECK-NEXT: [[R:%.*]] = fneg fast float [[X:%.*]]
273273
; CHECK-NEXT: ret float [[R]]
274274
;
275275
%a = fadd float %x, %y
@@ -283,7 +283,7 @@ define float @fsub_fadd_common_op_fneg(float %x, float %y) {
283283

284284
define float @fsub_fadd_common_op_fneg_reassoc_nsz(float %x, float %y) {
285285
; CHECK-LABEL: @fsub_fadd_common_op_fneg_reassoc_nsz(
286-
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]]
286+
; CHECK-NEXT: [[R:%.*]] = fneg reassoc nsz float [[X:%.*]]
287287
; CHECK-NEXT: ret float [[R]]
288288
;
289289
%a = fadd float %x, %y
@@ -295,7 +295,7 @@ define float @fsub_fadd_common_op_fneg_reassoc_nsz(float %x, float %y) {
295295

296296
define <2 x float> @fsub_fadd_common_op_fneg_vec(<2 x float> %x, <2 x float> %y) {
297297
; CHECK-LABEL: @fsub_fadd_common_op_fneg_vec(
298-
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
298+
; CHECK-NEXT: [[R:%.*]] = fneg reassoc nsz <2 x float> [[X:%.*]]
299299
; CHECK-NEXT: ret <2 x float> [[R]]
300300
;
301301
%a = fadd <2 x float> %x, %y
@@ -308,7 +308,7 @@ define <2 x float> @fsub_fadd_common_op_fneg_vec(<2 x float> %x, <2 x float> %y)
308308

309309
define float @fsub_fadd_common_op_fneg_commute(float %x, float %y) {
310310
; CHECK-LABEL: @fsub_fadd_common_op_fneg_commute(
311-
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]]
311+
; CHECK-NEXT: [[R:%.*]] = fneg reassoc nsz float [[X:%.*]]
312312
; CHECK-NEXT: ret float [[R]]
313313
;
314314
%a = fadd float %y, %x
@@ -320,7 +320,7 @@ define float @fsub_fadd_common_op_fneg_commute(float %x, float %y) {
320320

321321
define <2 x float> @fsub_fadd_common_op_fneg_commute_vec(<2 x float> %x, <2 x float> %y) {
322322
; CHECK-LABEL: @fsub_fadd_common_op_fneg_commute_vec(
323-
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
323+
; CHECK-NEXT: [[R:%.*]] = fneg reassoc nsz <2 x float> [[X:%.*]]
324324
; CHECK-NEXT: ret <2 x float> [[R]]
325325
;
326326
%a = fadd <2 x float> %y, %x
@@ -333,7 +333,7 @@ define <2 x float> @fsub_fadd_common_op_fneg_commute_vec(<2 x float> %x, <2 x fl
333333

334334
define float @fsub_fsub_common_op_fneg(float %x, float %y) {
335335
; CHECK-LABEL: @fsub_fsub_common_op_fneg(
336-
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz float -0.000000e+00, [[X:%.*]]
336+
; CHECK-NEXT: [[R:%.*]] = fneg reassoc nsz float [[X:%.*]]
337337
; CHECK-NEXT: ret float [[R]]
338338
;
339339
%s = fsub float %y, %x
@@ -345,7 +345,7 @@ define float @fsub_fsub_common_op_fneg(float %x, float %y) {
345345

346346
define <2 x float> @fsub_fsub_common_op_fneg_vec(<2 x float> %x, <2 x float> %y) {
347347
; CHECK-LABEL: @fsub_fsub_common_op_fneg_vec(
348-
; CHECK-NEXT: [[R:%.*]] = fsub reassoc nsz <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
348+
; CHECK-NEXT: [[R:%.*]] = fneg reassoc nsz <2 x float> [[X:%.*]]
349349
; CHECK-NEXT: ret <2 x float> [[R]]
350350
;
351351
%s = fsub <2 x float> %y, %x
@@ -534,7 +534,7 @@ define float @fneg1(float %f1, float %f2) {
534534

535535
define float @fneg2(float %x) {
536536
; CHECK-LABEL: @fneg2(
537-
; CHECK-NEXT: [[SUB:%.*]] = fsub nsz float -0.000000e+00, [[X:%.*]]
537+
; CHECK-NEXT: [[SUB:%.*]] = fneg nsz float [[X:%.*]]
538538
; CHECK-NEXT: ret float [[SUB]]
539539
;
540540
%sub = fsub nsz float 0.0, %x
@@ -543,7 +543,7 @@ define float @fneg2(float %x) {
543543

544544
define <2 x float> @fneg2_vec_undef(<2 x float> %x) {
545545
; CHECK-LABEL: @fneg2_vec_undef(
546-
; CHECK-NEXT: [[SUB:%.*]] = fsub nsz <2 x float> <float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
546+
; CHECK-NEXT: [[SUB:%.*]] = fneg nsz <2 x float> [[X:%.*]]
547547
; CHECK-NEXT: ret <2 x float> [[SUB]]
548548
;
549549
%sub = fsub nsz <2 x float> <float undef, float 0.0>, %x

llvm/test/Transforms/InstCombine/fmul.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ define <2 x float> @neg_mul_vec_undef(<2 x float> %x, <2 x float> %y) {
336336
; (0.0 - X) * Y
337337
define float @neg_sink_nsz(float %x, float %y) {
338338
; CHECK-LABEL: @neg_sink_nsz(
339-
; CHECK-NEXT: [[SUB1:%.*]] = fsub nsz float -0.000000e+00, [[X:%.*]]
339+
; CHECK-NEXT: [[SUB1:%.*]] = fneg nsz float [[X:%.*]]
340340
; CHECK-NEXT: [[MUL:%.*]] = fmul float [[SUB1]], [[Y:%.*]]
341341
; CHECK-NEXT: ret float [[MUL]]
342342
;
@@ -409,7 +409,7 @@ for.end: ; preds = %for.cond
409409
; X * -1.0 => -0.0 - X
410410
define float @test9(float %x) {
411411
; CHECK-LABEL: @test9(
412-
; CHECK-NEXT: [[MUL:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
412+
; CHECK-NEXT: [[MUL:%.*]] = fneg float [[X:%.*]]
413413
; CHECK-NEXT: ret float [[MUL]]
414414
;
415415
%mul = fmul float %x, -1.0
@@ -419,7 +419,7 @@ define float @test9(float %x) {
419419
; PR18532
420420
define <4 x float> @test10(<4 x float> %x) {
421421
; CHECK-LABEL: @test10(
422-
; CHECK-NEXT: [[MUL:%.*]] = fsub arcp afn <4 x float> <float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00>, [[X:%.*]]
422+
; CHECK-NEXT: [[MUL:%.*]] = fneg arcp afn <4 x float> [[X:%.*]]
423423
; CHECK-NEXT: ret <4 x float> [[MUL]]
424424
;
425425
%mul = fmul arcp afn <4 x float> %x, <float -1.0, float -1.0, float -1.0, float -1.0>

llvm/test/Transforms/InstCombine/fneg.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ define float @fsub_fsub_sel_extra_use1(float %x, float %y, i1 %cond) {
349349
; CHECK-NEXT: [[N1:%.*]] = fsub float -0.000000e+00, [[X:%.*]]
350350
; CHECK-NEXT: call void @use(float [[N1]])
351351
; CHECK-NEXT: [[SEL_V:%.*]] = select i1 [[COND:%.*]], float [[X]], float [[Y:%.*]]
352-
; CHECK-NEXT: [[SEL:%.*]] = fsub float -0.000000e+00, [[SEL_V]]
352+
; CHECK-NEXT: [[SEL:%.*]] = fneg float [[SEL_V]]
353353
; CHECK-NEXT: ret float [[SEL]]
354354
;
355355
%n1 = fsub float -0.0, %x

llvm/test/Transforms/InstCombine/fpcast.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ define half @test3(float %a) {
3232
define half @fneg_fptrunc(float %a) {
3333
; CHECK-LABEL: @fneg_fptrunc(
3434
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
35-
; CHECK-NEXT: [[C:%.*]] = fsub half 0xH8000, [[TMP1]]
35+
; CHECK-NEXT: [[C:%.*]] = fneg half [[TMP1]]
3636
; CHECK-NEXT: ret half [[C]]
3737
;
3838
%b = fsub float -0.0, %a
@@ -54,7 +54,7 @@ define half @unary_fneg_fptrunc(float %a) {
5454
define <2 x half> @fneg_fptrunc_vec_undef(<2 x float> %a) {
5555
; CHECK-LABEL: @fneg_fptrunc_vec_undef(
5656
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x float> [[A:%.*]] to <2 x half>
57-
; CHECK-NEXT: [[C:%.*]] = fsub <2 x half> <half 0xH8000, half 0xH8000>, [[TMP1]]
57+
; CHECK-NEXT: [[C:%.*]] = fneg <2 x half> [[TMP1]]
5858
; CHECK-NEXT: ret <2 x half> [[C]]
5959
;
6060
%b = fsub <2 x float> <float -0.0, float undef>, %a
@@ -76,7 +76,7 @@ define <2 x half> @unary_fneg_fptrunc_vec(<2 x float> %a) {
7676
define half @test4-fast(float %a) {
7777
; CHECK-LABEL: @test4-fast(
7878
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[A:%.*]] to half
79-
; CHECK-NEXT: [[C:%.*]] = fsub fast half 0xH8000, [[TMP1]]
79+
; CHECK-NEXT: [[C:%.*]] = fneg fast half [[TMP1]]
8080
; CHECK-NEXT: ret half [[C]]
8181
;
8282
%b = fsub fast float -0.0, %a

llvm/test/Transforms/InstCombine/fsub.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ define float @unary_neg_ext_op1_extra_use(half %a, float %b) {
331331
define float @neg_trunc_op1_extra_use(double %a, float %b) {
332332
; CHECK-LABEL: @neg_trunc_op1_extra_use(
333333
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[A:%.*]] to float
334-
; CHECK-NEXT: [[T2:%.*]] = fsub float -0.000000e+00, [[TMP1]]
334+
; CHECK-NEXT: [[T2:%.*]] = fneg float [[TMP1]]
335335
; CHECK-NEXT: [[T3:%.*]] = fadd float [[TMP1]], [[B:%.*]]
336336
; CHECK-NEXT: call void @use(float [[T2]])
337337
; CHECK-NEXT: ret float [[T3]]

0 commit comments

Comments
 (0)