Skip to content

Commit 3d494bf

Browse files
authored
[SimplifyCFG] Increase budget for FoldTwoEntryPHINode() if the branch is unpredictable. (#98495)
The `!unpredictable` metadata has been present for a long time, but it's usage in optimizations is still limited. This patch teaches `FoldTwoEntryPHINode()` to be more aggressive with an unpredictable branch to reduce mispredictions. A TTI interface `getBranchMispredictPenalty()` is added to distinguish between different hardwares to ensure we don't go too far for simpler cores. For simplicity, only a naive x86 implementation is included for the time being.
1 parent b6dbda6 commit 3d494bf

12 files changed

+158
-13
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ class TargetTransformInfo {
419419
/// this factor, it is very likely to be predicted correctly.
420420
BranchProbability getPredictableBranchThreshold() const;
421421

422+
/// Returns estimated penalty of a branch misprediction in latency. Indicates
423+
/// how aggressive the target wants for eliminating unpredictable branches. A
424+
/// zero return value means extra optimization applied to them should be
425+
/// minimal.
426+
InstructionCost getBranchMispredictPenalty() const;
427+
422428
/// Return true if branch divergence exists.
423429
///
424430
/// Branch divergence has a significantly negative impact on GPU performance
@@ -1832,6 +1838,7 @@ class TargetTransformInfo::Concept {
18321838
ArrayRef<const Value *> Operands,
18331839
TargetCostKind CostKind) = 0;
18341840
virtual BranchProbability getPredictableBranchThreshold() = 0;
1841+
virtual InstructionCost getBranchMispredictPenalty() = 0;
18351842
virtual bool hasBranchDivergence(const Function *F = nullptr) = 0;
18361843
virtual bool isSourceOfDivergence(const Value *V) = 0;
18371844
virtual bool isAlwaysUniform(const Value *V) = 0;
@@ -2243,6 +2250,9 @@ class TargetTransformInfo::Model final : public TargetTransformInfo::Concept {
22432250
BranchProbability getPredictableBranchThreshold() override {
22442251
return Impl.getPredictableBranchThreshold();
22452252
}
2253+
InstructionCost getBranchMispredictPenalty() override {
2254+
return Impl.getBranchMispredictPenalty();
2255+
}
22462256
bool hasBranchDivergence(const Function *F = nullptr) override {
22472257
return Impl.hasBranchDivergence(F);
22482258
}

llvm/include/llvm/Analysis/TargetTransformInfoImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class TargetTransformInfoImplBase {
9999
return BranchProbability(99, 100);
100100
}
101101

102+
InstructionCost getBranchMispredictPenalty() const { return 0; }
103+
102104
bool hasBranchDivergence(const Function *F = nullptr) const { return false; }
103105

104106
bool isSourceOfDivergence(const Value *V) const { return false; }

llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct SimplifyCFGOptions {
3030
bool SinkCommonInsts = false;
3131
bool SimplifyCondBranch = true;
3232
bool SpeculateBlocks = true;
33+
bool SpeculateUnpredictables = false;
3334

3435
AssumptionCache *AC = nullptr;
3536

@@ -75,6 +76,10 @@ struct SimplifyCFGOptions {
7576
SpeculateBlocks = B;
7677
return *this;
7778
}
79+
SimplifyCFGOptions &speculateUnpredictables(bool B) {
80+
SpeculateUnpredictables = B;
81+
return *this;
82+
}
7883
};
7984

8085
} // namespace llvm

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ BranchProbability TargetTransformInfo::getPredictableBranchThreshold() const {
279279
: TTIImpl->getPredictableBranchThreshold();
280280
}
281281

282+
InstructionCost TargetTransformInfo::getBranchMispredictPenalty() const {
283+
return TTIImpl->getBranchMispredictPenalty();
284+
}
285+
282286
bool TargetTransformInfo::hasBranchDivergence(const Function *F) const {
283287
return TTIImpl->hasBranchDivergence(F);
284288
}

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,8 @@ Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
845845
Result.hoistCommonInsts(Enable);
846846
} else if (ParamName == "sink-common-insts") {
847847
Result.sinkCommonInsts(Enable);
848+
} else if (ParamName == "speculate-unpredictables") {
849+
Result.speculateUnpredictables(Enable);
848850
} else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
849851
APInt BonusInstThreshold;
850852
if (ParamName.getAsInteger(0, BonusInstThreshold))

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,8 +1515,9 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
15151515

15161516
// LoopSink (and other loop passes since the last simplifyCFG) might have
15171517
// resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
1518-
OptimizePM.addPass(
1519-
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
1518+
OptimizePM.addPass(SimplifyCFGPass(SimplifyCFGOptions()
1519+
.convertSwitchRangeToICmp(true)
1520+
.speculateUnpredictables(true)));
15201521

15211522
// Add the core optimizing pipeline.
15221523
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM),
@@ -2034,9 +2035,10 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
20342035
LateFPM.addPass(DivRemPairsPass());
20352036

20362037
// Delete basic blocks, which optimization passes may have killed.
2037-
LateFPM.addPass(SimplifyCFGPass(
2038-
SimplifyCFGOptions().convertSwitchRangeToICmp(true).hoistCommonInsts(
2039-
true)));
2038+
LateFPM.addPass(SimplifyCFGPass(SimplifyCFGOptions()
2039+
.convertSwitchRangeToICmp(true)
2040+
.hoistCommonInsts(true)
2041+
.speculateUnpredictables(true)));
20402042
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
20412043

20422044
// Drop bodies of available eternally objects to improve GlobalDCE.

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6756,3 +6756,8 @@ InstructionCost X86TTIImpl::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV,
67566756
return AM.Scale != 0;
67576757
return -1;
67586758
}
6759+
6760+
InstructionCost X86TTIImpl::getBranchMispredictPenalty() const {
6761+
// TODO: Hook MispredictPenalty of SchedMachineModel into this.
6762+
return 14;
6763+
}

llvm/lib/Target/X86/X86TargetTransformInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ class X86TTIImpl : public BasicTTIImplBase<X86TTIImpl> {
294294
bool supportsEfficientVectorElementLoadStore() const;
295295
bool enableInterleavedAccessVectorization();
296296

297+
InstructionCost getBranchMispredictPenalty() const;
298+
297299
private:
298300
bool supportsGather() const;
299301
InstructionCost getGSVectorCost(unsigned Opcode, TTI::TargetCostKind CostKind,

llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static cl::opt<bool> UserSinkCommonInsts(
7777
"sink-common-insts", cl::Hidden, cl::init(false),
7878
cl::desc("Sink common instructions (default = false)"));
7979

80+
static cl::opt<bool> UserSpeculateUnpredictables(
81+
"speculate-unpredictables", cl::Hidden, cl::init(false),
82+
cl::desc("Speculate unpredictable branches (default = false)"));
8083

8184
STATISTIC(NumSimpl, "Number of blocks simplified");
8285

@@ -325,6 +328,8 @@ static void applyCommandLineOverridesToOptions(SimplifyCFGOptions &Options) {
325328
Options.HoistCommonInsts = UserHoistCommonInsts;
326329
if (UserSinkCommonInsts.getNumOccurrences())
327330
Options.SinkCommonInsts = UserSinkCommonInsts;
331+
if (UserSpeculateUnpredictables.getNumOccurrences())
332+
Options.SpeculateUnpredictables = UserSpeculateUnpredictables;
328333
}
329334

330335
SimplifyCFGPass::SimplifyCFGPass() {
@@ -351,7 +356,9 @@ void SimplifyCFGPass::printPipeline(
351356
OS << (Options.HoistCommonInsts ? "" : "no-") << "hoist-common-insts;";
352357
OS << (Options.SinkCommonInsts ? "" : "no-") << "sink-common-insts;";
353358
OS << (Options.SpeculateBlocks ? "" : "no-") << "speculate-blocks;";
354-
OS << (Options.SimplifyCondBranch ? "" : "no-") << "simplify-cond-branch";
359+
OS << (Options.SimplifyCondBranch ? "" : "no-") << "simplify-cond-branch;";
360+
OS << (Options.SpeculateUnpredictables ? "" : "no-")
361+
<< "speculate-unpredictables";
355362
OS << '>';
356363
}
357364

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,7 +3476,8 @@ static bool FoldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
34763476
/// Given a BB that starts with the specified two-entry PHI node,
34773477
/// see if we can eliminate it.
34783478
static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
3479-
DomTreeUpdater *DTU, const DataLayout &DL) {
3479+
DomTreeUpdater *DTU, const DataLayout &DL,
3480+
bool SpeculateUnpredictables) {
34803481
// Ok, this is a two entry PHI node. Check to see if this is a simple "if
34813482
// statement", which has a very simple dominance structure. Basically, we
34823483
// are trying to find the condition that is being branched on, which
@@ -3508,7 +3509,8 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
35083509
// jump to one specific 'then' block (if we have two of them).
35093510
// It isn't beneficial to speculatively execute the code
35103511
// from the block that we know is predictably not entered.
3511-
if (!DomBI->getMetadata(LLVMContext::MD_unpredictable)) {
3512+
bool IsUnpredictable = DomBI->getMetadata(LLVMContext::MD_unpredictable);
3513+
if (!IsUnpredictable) {
35123514
uint64_t TWeight, FWeight;
35133515
if (extractBranchWeights(*DomBI, TWeight, FWeight) &&
35143516
(TWeight + FWeight) != 0) {
@@ -3551,6 +3553,8 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
35513553
InstructionCost Cost = 0;
35523554
InstructionCost Budget =
35533555
TwoEntryPHINodeFoldingThreshold * TargetTransformInfo::TCC_Basic;
3556+
if (SpeculateUnpredictables && IsUnpredictable)
3557+
Budget += TTI.getBranchMispredictPenalty();
35543558

35553559
bool Changed = false;
35563560
for (BasicBlock::iterator II = BB->begin(); isa<PHINode>(II);) {
@@ -3620,8 +3624,9 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
36203624
[](BasicBlock *IfBlock) { return IfBlock->hasAddressTaken(); }))
36213625
return Changed;
36223626

3623-
LLVM_DEBUG(dbgs() << "FOUND IF CONDITION! " << *IfCond
3624-
<< " T: " << IfTrue->getName()
3627+
LLVM_DEBUG(dbgs() << "FOUND IF CONDITION! " << *IfCond;
3628+
if (IsUnpredictable) dbgs() << " (unpredictable)";
3629+
dbgs() << " T: " << IfTrue->getName()
36253630
<< " F: " << IfFalse->getName() << "\n");
36263631

36273632
// If we can still promote the PHI nodes after this gauntlet of tests,
@@ -7814,7 +7819,8 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
78147819
// eliminate it, do so now.
78157820
if (auto *PN = dyn_cast<PHINode>(BB->begin()))
78167821
if (PN->getNumIncomingValues() == 2)
7817-
if (FoldTwoEntryPHINode(PN, TTI, DTU, DL))
7822+
if (FoldTwoEntryPHINode(PN, TTI, DTU, DL,
7823+
Options.SpeculateUnpredictables))
78187824
return true;
78197825
}
78207826

llvm/test/Other/new-pm-print-pipeline.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(print<stack-lifetime><may>,print<stack-lifetime><must>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-17
5050
; CHECK-17: function(print<stack-lifetime><may>,print<stack-lifetime><must>)
5151

52-
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(simplifycfg<bonus-inst-threshold=5;forward-switch-cond;switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,simplifycfg<bonus-inst-threshold=7;no-forward-switch-cond;no-switch-to-lookup;no-keep-loops;no-hoist-common-insts;no-sink-common-insts;no-speculate-blocks;no-simplify-cond-branch>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-18
53-
; CHECK-18: function(simplifycfg<bonus-inst-threshold=5;forward-switch-cond;no-switch-range-to-icmp;switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,simplifycfg<bonus-inst-threshold=7;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;no-keep-loops;no-hoist-common-insts;no-sink-common-insts;no-speculate-blocks;no-simplify-cond-branch>)
52+
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(simplifycfg<bonus-inst-threshold=5;forward-switch-cond;switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>,simplifycfg<bonus-inst-threshold=7;no-forward-switch-cond;no-switch-to-lookup;no-keep-loops;no-hoist-common-insts;no-sink-common-insts;no-speculate-blocks;no-simplify-cond-branch;no-speculate-unpredictables>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-18
53+
; CHECK-18: function(simplifycfg<bonus-inst-threshold=5;forward-switch-cond;no-switch-range-to-icmp;switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>,simplifycfg<bonus-inst-threshold=7;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;no-keep-loops;no-hoist-common-insts;no-sink-common-insts;no-speculate-blocks;no-simplify-cond-branch;no-speculate-unpredictables>)
5454

5555
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only>,loop-vectorize<interleave-forced-only;vectorize-forced-only>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-19
5656
; CHECK-19: function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,loop-vectorize<interleave-forced-only;vectorize-forced-only;>)
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 5
2+
; Two-entry phi nodes with unpredictable conditions may get increased budget for folding.
3+
; RUN: opt < %s -S -passes=simplifycfg | FileCheck --check-prefix=CHECK-NOFOLD %s
4+
; RUN: opt < %s -S -passes='simplifycfg<speculate-unpredictables>' | FileCheck --check-prefix=CHECK-NOFOLD %s
5+
; RUN: opt -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 < %s -S -passes=simplifycfg | FileCheck --check-prefix=CHECK-NOFOLD %s
6+
; RUN: opt -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 < %s -S -passes='simplifycfg<speculate-unpredictables>' | FileCheck --check-prefix=CHECK-FOLD %s
7+
8+
define { <2 x float>, <2 x float> } @foo(float %arg, <2 x float> %arg1, <2 x float> %arg2) #0 {
9+
; CHECK-NOFOLD-LABEL: define { <2 x float>, <2 x float> } @foo(
10+
; CHECK-NOFOLD-SAME: float [[ARG:%.*]], <2 x float> [[ARG1:%.*]], <2 x float> [[ARG2:%.*]]) #[[ATTR0:[0-9]+]] {
11+
; CHECK-NOFOLD-NEXT: [[BB:.*]]:
12+
; CHECK-NOFOLD-NEXT: [[I:%.*]] = fcmp fast ogt float [[ARG]], 0x3F747AE140000000
13+
; CHECK-NOFOLD-NEXT: br i1 [[I]], label %[[BB3:.*]], label %[[BB20:.*]], !unpredictable [[META0:![0-9]+]]
14+
; CHECK-NOFOLD: [[BB3]]:
15+
; CHECK-NOFOLD-NEXT: [[I4:%.*]] = extractelement <2 x float> [[ARG1]], i64 0
16+
; CHECK-NOFOLD-NEXT: [[I5:%.*]] = fmul fast float [[I4]], [[I4]]
17+
; CHECK-NOFOLD-NEXT: [[I6:%.*]] = extractelement <2 x float> [[ARG1]], i64 1
18+
; CHECK-NOFOLD-NEXT: [[I7:%.*]] = fmul fast float [[I6]], [[I6]]
19+
; CHECK-NOFOLD-NEXT: [[I8:%.*]] = fadd fast float [[I7]], [[I5]]
20+
; CHECK-NOFOLD-NEXT: [[I9:%.*]] = extractelement <2 x float> [[ARG2]], i64 0
21+
; CHECK-NOFOLD-NEXT: [[I10:%.*]] = fmul fast float [[I9]], [[I9]]
22+
; CHECK-NOFOLD-NEXT: [[I11:%.*]] = fadd fast float [[I8]], [[I10]]
23+
; CHECK-NOFOLD-NEXT: [[I12:%.*]] = tail call fast noundef float @llvm.sqrt.f32(float [[I11]])
24+
; CHECK-NOFOLD-NEXT: [[I13:%.*]] = fdiv fast float 0x3FEFD70A40000000, [[I12]]
25+
; CHECK-NOFOLD-NEXT: [[I14:%.*]] = fmul fast float [[I13]], [[I4]]
26+
; CHECK-NOFOLD-NEXT: [[I15:%.*]] = insertelement <2 x float> poison, float [[I14]], i64 0
27+
; CHECK-NOFOLD-NEXT: [[I16:%.*]] = fmul fast float [[I13]], [[I6]]
28+
; CHECK-NOFOLD-NEXT: [[I17:%.*]] = insertelement <2 x float> [[I15]], float [[I16]], i64 1
29+
; CHECK-NOFOLD-NEXT: [[I18:%.*]] = fmul fast float [[I13]], [[I9]]
30+
; CHECK-NOFOLD-NEXT: [[I19:%.*]] = insertelement <2 x float> [[ARG2]], float [[I18]], i64 0
31+
; CHECK-NOFOLD-NEXT: br label %[[BB20]]
32+
; CHECK-NOFOLD: [[BB20]]:
33+
; CHECK-NOFOLD-NEXT: [[I21:%.*]] = phi nsz <2 x float> [ [[I17]], %[[BB3]] ], [ zeroinitializer, %[[BB]] ]
34+
; CHECK-NOFOLD-NEXT: [[I22:%.*]] = phi nsz <2 x float> [ [[I19]], %[[BB3]] ], [ zeroinitializer, %[[BB]] ]
35+
; CHECK-NOFOLD-NEXT: [[I23:%.*]] = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> [[I21]], 0
36+
; CHECK-NOFOLD-NEXT: [[I24:%.*]] = insertvalue { <2 x float>, <2 x float> } [[I23]], <2 x float> [[I22]], 1
37+
; CHECK-NOFOLD-NEXT: ret { <2 x float>, <2 x float> } [[I24]]
38+
;
39+
; CHECK-FOLD-LABEL: define { <2 x float>, <2 x float> } @foo(
40+
; CHECK-FOLD-SAME: float [[ARG:%.*]], <2 x float> [[ARG1:%.*]], <2 x float> [[ARG2:%.*]]) #[[ATTR0:[0-9]+]] {
41+
; CHECK-FOLD-NEXT: [[BB:.*:]]
42+
; CHECK-FOLD-NEXT: [[I:%.*]] = fcmp fast ogt float [[ARG]], 0x3F747AE140000000
43+
; CHECK-FOLD-NEXT: [[I4:%.*]] = extractelement <2 x float> [[ARG1]], i64 0
44+
; CHECK-FOLD-NEXT: [[I5:%.*]] = fmul fast float [[I4]], [[I4]]
45+
; CHECK-FOLD-NEXT: [[I6:%.*]] = extractelement <2 x float> [[ARG1]], i64 1
46+
; CHECK-FOLD-NEXT: [[I7:%.*]] = fmul fast float [[I6]], [[I6]]
47+
; CHECK-FOLD-NEXT: [[I8:%.*]] = fadd fast float [[I7]], [[I5]]
48+
; CHECK-FOLD-NEXT: [[I9:%.*]] = extractelement <2 x float> [[ARG2]], i64 0
49+
; CHECK-FOLD-NEXT: [[I10:%.*]] = fmul fast float [[I9]], [[I9]]
50+
; CHECK-FOLD-NEXT: [[I11:%.*]] = fadd fast float [[I8]], [[I10]]
51+
; CHECK-FOLD-NEXT: [[I12:%.*]] = tail call fast float @llvm.sqrt.f32(float [[I11]])
52+
; CHECK-FOLD-NEXT: [[I13:%.*]] = fdiv fast float 0x3FEFD70A40000000, [[I12]]
53+
; CHECK-FOLD-NEXT: [[I14:%.*]] = fmul fast float [[I13]], [[I4]]
54+
; CHECK-FOLD-NEXT: [[I15:%.*]] = insertelement <2 x float> poison, float [[I14]], i64 0
55+
; CHECK-FOLD-NEXT: [[I16:%.*]] = fmul fast float [[I13]], [[I6]]
56+
; CHECK-FOLD-NEXT: [[I17:%.*]] = insertelement <2 x float> [[I15]], float [[I16]], i64 1
57+
; CHECK-FOLD-NEXT: [[I18:%.*]] = fmul fast float [[I13]], [[I9]]
58+
; CHECK-FOLD-NEXT: [[I19:%.*]] = insertelement <2 x float> [[ARG2]], float [[I18]], i64 0
59+
; CHECK-FOLD-NEXT: [[I21:%.*]] = select nsz i1 [[I]], <2 x float> [[I17]], <2 x float> zeroinitializer, !unpredictable [[META0:![0-9]+]]
60+
; CHECK-FOLD-NEXT: [[I22:%.*]] = select nsz i1 [[I]], <2 x float> [[I19]], <2 x float> zeroinitializer, !unpredictable [[META0]]
61+
; CHECK-FOLD-NEXT: [[I23:%.*]] = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> [[I21]], 0
62+
; CHECK-FOLD-NEXT: [[I24:%.*]] = insertvalue { <2 x float>, <2 x float> } [[I23]], <2 x float> [[I22]], 1
63+
; CHECK-FOLD-NEXT: ret { <2 x float>, <2 x float> } [[I24]]
64+
;
65+
bb:
66+
%i = fcmp fast ogt float %arg, 0x3F747AE140000000
67+
br i1 %i, label %bb3, label %bb20, !unpredictable !0
68+
69+
bb3: ; preds = %bb
70+
%i4 = extractelement <2 x float> %arg1, i64 0
71+
%i5 = fmul fast float %i4, %i4
72+
%i6 = extractelement <2 x float> %arg1, i64 1
73+
%i7 = fmul fast float %i6, %i6
74+
%i8 = fadd fast float %i7, %i5
75+
%i9 = extractelement <2 x float> %arg2, i64 0
76+
%i10 = fmul fast float %i9, %i9
77+
%i11 = fadd fast float %i8, %i10
78+
%i12 = tail call fast noundef float @llvm.sqrt.f32(float %i11)
79+
%i13 = fdiv fast float 0x3FEFD70A40000000, %i12
80+
%i14 = fmul fast float %i13, %i4
81+
%i15 = insertelement <2 x float> poison, float %i14, i64 0
82+
%i16 = fmul fast float %i13, %i6
83+
%i17 = insertelement <2 x float> %i15, float %i16, i64 1
84+
%i18 = fmul fast float %i13, %i9
85+
%i19 = insertelement <2 x float> %arg2, float %i18, i64 0
86+
br label %bb20
87+
88+
bb20: ; preds = %bb3, %bb
89+
%i21 = phi nsz <2 x float> [ %i17, %bb3 ], [ zeroinitializer, %bb ]
90+
%i22 = phi nsz <2 x float> [ %i19, %bb3 ], [ zeroinitializer, %bb ]
91+
%i23 = insertvalue { <2 x float>, <2 x float> } poison, <2 x float> %i21, 0
92+
%i24 = insertvalue { <2 x float>, <2 x float> } %i23, <2 x float> %i22, 1
93+
ret { <2 x float>, <2 x float> } %i24
94+
}
95+
96+
declare float @llvm.sqrt.f32(float)
97+
98+
attributes #0 = { nounwind }
99+
100+
!0 = !{}

0 commit comments

Comments
 (0)