Skip to content

Commit 2cec4b5

Browse files
committed
Revert [IR] allow fast-math-flags on phi of FP values
This reverts r372866 (git commit dec0322) llvm-svn: 372868
1 parent 7915260 commit 2cec4b5

File tree

10 files changed

+14
-86
lines changed

10 files changed

+14
-86
lines changed

llvm/docs/LangRef.rst

+1-7
Original file line numberDiff line numberDiff line change
@@ -10067,7 +10067,7 @@ Syntax:
1006710067

1006810068
::
1006910069

10070-
<result> = phi [fast-math-flags] <ty> [ <val0>, <label0>], ...
10070+
<result> = phi <ty> [ <val0>, <label0>], ...
1007110071

1007210072
Overview:
1007310073
"""""""""
@@ -10094,12 +10094,6 @@ deemed to occur on the edge from the corresponding predecessor block to
1009410094
the current block (but after any definition of an '``invoke``'
1009510095
instruction's return value on the same edge).
1009610096

10097-
The optional ``fast-math-flags`` marker indicates that the phi has one
10098-
or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
10099-
to enable otherwise unsafe floating-point optimizations. Fast-math-flags
10100-
are only valid for phis that return a floating-point scalar or vector
10101-
type.
10102-
1010310097
Semantics:
1010410098
""""""""""
1010510099

llvm/include/llvm/IR/IRBuilder.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -2231,10 +2231,7 @@ class IRBuilder : public IRBuilderBase, public Inserter {
22312231

22322232
PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
22332233
const Twine &Name = "") {
2234-
PHINode *Phi = PHINode::Create(Ty, NumReservedValues);
2235-
if (isa<FPMathOperator>(Phi))
2236-
Phi = cast<PHINode>(setFPAttrs(Phi, nullptr /* MDNode* */, FMF));
2237-
return Insert(Phi, Name);
2234+
return Insert(PHINode::Create(Ty, NumReservedValues), Name);
22382235
}
22392236

22402237
CallInst *CreateCall(FunctionType *FTy, Value *Callee,

llvm/include/llvm/IR/Operator.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,13 @@ class FPMathOperator : public Operator {
379379
return false;
380380

381381
switch (Opcode) {
382-
// FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
383-
// should not be treated as a math op, but the other opcodes should.
384-
// This would make things consistent with Select/PHI (FP value type
385-
// determines whether they are math ops and, therefore, capable of
386-
// having fast-math-flags).
387382
case Instruction::FCmp:
388383
return true;
389384
// non math FP Operators (no FMF)
390385
case Instruction::ExtractElement:
391386
case Instruction::ShuffleVector:
392387
case Instruction::InsertElement:
388+
case Instruction::PHI:
393389
return false;
394390
default:
395391
return V->getType()->isFPOrFPVectorTy();

llvm/lib/Analysis/IVDescriptors.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ bool RecurrenceDescriptor::AddReductionVar(PHINode *Phi, RecurrenceKind Kind,
300300
ReduxDesc = isRecurrenceInstr(Cur, Kind, ReduxDesc, HasFunNoNaNAttr);
301301
if (!ReduxDesc.isRecurrence())
302302
return false;
303-
// FIXME: FMF is allowed on phi, but propagation is not handled correctly.
304-
if (isa<FPMathOperator>(ReduxDesc.getPatternInst()) && !IsAPhi)
303+
if (isa<FPMathOperator>(ReduxDesc.getPatternInst()))
305304
FMF &= ReduxDesc.getPatternInst()->getFastMathFlags();
306305
}
307306

llvm/lib/AsmParser/LLParser.cpp

+1-13
Original file line numberDiff line numberDiff line change
@@ -5802,19 +5802,7 @@ int LLParser::ParseInstruction(Instruction *&Inst, BasicBlock *BB,
58025802
case lltok::kw_extractelement: return ParseExtractElement(Inst, PFS);
58035803
case lltok::kw_insertelement: return ParseInsertElement(Inst, PFS);
58045804
case lltok::kw_shufflevector: return ParseShuffleVector(Inst, PFS);
5805-
case lltok::kw_phi: {
5806-
FastMathFlags FMF = EatFastMathFlagsIfPresent();
5807-
int Res = ParsePHI(Inst, PFS);
5808-
if (Res != 0)
5809-
return Res;
5810-
if (FMF.any()) {
5811-
if (!Inst->getType()->isFPOrFPVectorTy())
5812-
return Error(Loc, "fast-math-flags specified for phi without "
5813-
"floating-point scalar or vector return type");
5814-
Inst->setFastMathFlags(FMF);
5815-
}
5816-
return 0;
5817-
}
5805+
case lltok::kw_phi: return ParsePHI(Inst, PFS);
58185806
case lltok::kw_landingpad: return ParseLandingPad(Inst, PFS);
58195807
// Call.
58205808
case lltok::kw_call: return ParseCall(Inst, PFS, CallInst::TCK_None);

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+6-23
Original file line numberDiff line numberDiff line change
@@ -4629,48 +4629,31 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
46294629
InstructionList.push_back(I);
46304630
break;
46314631
case bitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...]
4632-
if (Record.size() < 1)
4632+
if (Record.size() < 1 || ((Record.size()-1)&1))
46334633
return error("Invalid record");
4634-
// The first record specifies the type.
46354634
FullTy = getFullyStructuredTypeByID(Record[0]);
46364635
Type *Ty = flattenPointerTypes(FullTy);
46374636
if (!Ty)
46384637
return error("Invalid record");
46394638

4640-
// Phi arguments are pairs of records of [value, basic block].
4641-
// There is an optional final record for fast-math-flags if this phi has a
4642-
// floating-point type.
4643-
size_t NumArgs = (Record.size() - 1) / 2;
4644-
if ((Record.size() - 1) % 2 == 1 && !Ty->isFloatingPointTy())
4645-
return error("Invalid record");
4646-
4647-
PHINode *PN = PHINode::Create(Ty, NumArgs);
4639+
PHINode *PN = PHINode::Create(Ty, (Record.size()-1)/2);
46484640
InstructionList.push_back(PN);
46494641

4650-
for (unsigned i = 0; i != NumArgs; i++) {
4642+
for (unsigned i = 0, e = Record.size()-1; i != e; i += 2) {
46514643
Value *V;
46524644
// With the new function encoding, it is possible that operands have
46534645
// negative IDs (for forward references). Use a signed VBR
46544646
// representation to keep the encoding small.
46554647
if (UseRelativeIDs)
4656-
V = getValueSigned(Record, i * 2 + 1, NextValueNo, Ty);
4648+
V = getValueSigned(Record, 1+i, NextValueNo, Ty);
46574649
else
4658-
V = getValue(Record, i * 2 + 1, NextValueNo, Ty);
4659-
BasicBlock *BB = getBasicBlock(Record[i * 2 + 2]);
4650+
V = getValue(Record, 1+i, NextValueNo, Ty);
4651+
BasicBlock *BB = getBasicBlock(Record[2+i]);
46604652
if (!V || !BB)
46614653
return error("Invalid record");
46624654
PN->addIncoming(V, BB);
46634655
}
46644656
I = PN;
4665-
4666-
// If there are an even number of records, the final record must be FMF.
4667-
if (Record.size() % 2 == 0) {
4668-
assert(isa<FPMathOperator>(I) && "Unexpected phi type");
4669-
FastMathFlags FMF = getDecodedFastMathFlags(Record[Record.size() - 1]);
4670-
if (FMF.any())
4671-
I->setFastMathFlags(FMF);
4672-
}
4673-
46744657
break;
46754658
}
46764659

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -2880,11 +2880,6 @@ void ModuleBitcodeWriter::writeInstruction(const Instruction &I,
28802880
pushValueSigned(PN.getIncomingValue(i), InstID, Vals64);
28812881
Vals64.push_back(VE.getValueID(PN.getIncomingBlock(i)));
28822882
}
2883-
2884-
uint64_t Flags = getOptimizationFlags(&I);
2885-
if (Flags != 0)
2886-
Vals64.push_back(Flags);
2887-
28882883
// Emit a Vals64 vector and exit.
28892884
Stream.EmitRecord(Code, Vals64, AbbrevToUse);
28902885
Vals64.clear();

llvm/lib/CodeGen/CodeGenPrepare.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5951,7 +5951,7 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
59515951
// If branch conversion isn't desirable, exit early.
59525952
if (DisableSelectToBranch || OptSize || !TLI)
59535953
return false;
5954-
TLI->isSelectSupported(<#SelectSupportKind#>)
5954+
59555955
// Find all consecutive select instructions that share the same condition.
59565956
SmallVector<SelectInst *, 2> ASI;
59575957
ASI.push_back(SI);

llvm/test/Bitcode/compatibility.ll

-21
Original file line numberDiff line numberDiff line change
@@ -861,27 +861,6 @@ define void @fastmathflags_vector_select(<2 x i1> %cond, <2 x double> %op1, <2 x
861861
ret void
862862
}
863863

864-
define void @fastmathflags_phi(i1 %cond, float %f1, float %f2, double %d1, double %d2, half %h1, half %h2) {
865-
entry:
866-
br i1 %cond, label %L1, label %L2
867-
L1:
868-
br label %exit
869-
L2:
870-
br label %exit
871-
exit:
872-
%p.nnan = phi nnan float [ %f1, %L1 ], [ %f2, %L2 ]
873-
; CHECK: %p.nnan = phi nnan float [ %f1, %L1 ], [ %f2, %L2 ]
874-
%p.ninf = phi ninf double [ %d1, %L1 ], [ %d2, %L2 ]
875-
; CHECK: %p.ninf = phi ninf double [ %d1, %L1 ], [ %d2, %L2 ]
876-
%p.contract = phi contract half [ %h1, %L1 ], [ %h2, %L2 ]
877-
; CHECK: %p.contract = phi contract half [ %h1, %L1 ], [ %h2, %L2 ]
878-
%p.nsz.reassoc = phi reassoc nsz float [ %f1, %L1 ], [ %f2, %L2 ]
879-
; CHECK: %p.nsz.reassoc = phi reassoc nsz float [ %f1, %L1 ], [ %f2, %L2 ]
880-
%p.fast = phi fast half [ %h2, %L1 ], [ %h1, %L2 ]
881-
; CHECK: %p.fast = phi fast half [ %h2, %L1 ], [ %h1, %L2 ]
882-
ret void
883-
}
884-
885864
; Check various fast math flags and floating-point types on calls.
886865

887866
declare float @fmf1()

llvm/unittests/IR/InstructionsTest.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -1034,16 +1034,13 @@ TEST(InstructionsTest, SkipDebug) {
10341034
EXPECT_EQ(nullptr, Term->getNextNonDebugInstruction());
10351035
}
10361036

1037-
TEST(InstructionsTest, PhiMightNotBeFPMathOperator) {
1037+
TEST(InstructionsTest, PhiIsNotFPMathOperator) {
10381038
LLVMContext Context;
10391039
IRBuilder<> Builder(Context);
10401040
MDBuilder MDHelper(Context);
1041-
Instruction *I = Builder.CreatePHI(Builder.getInt32Ty(), 0);
1041+
Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0);
10421042
EXPECT_FALSE(isa<FPMathOperator>(I));
10431043
I->deleteValue();
1044-
Instruction *FP = Builder.CreatePHI(Builder.getDoubleTy(), 0);
1045-
EXPECT_TRUE(isa<FPMathOperator>(FP));
1046-
FP->deleteValue();
10471044
}
10481045

10491046
TEST(InstructionsTest, FNegInstruction) {

0 commit comments

Comments
 (0)