[PATCH] D139075: [Instcombine] Code refactors for foldSelectOpOp; NFC
Simon Pilgrim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 1 06:32:01 PST 2022
RKSimon added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:317
- // Cond ? -X : -Y --> -(Cond ? X : Y)
- Value *X, *Y;
- if (match(TI, m_FNeg(m_Value(X))) && match(FI, m_FNeg(m_Value(Y))) &&
- (TI->hasOneUse() || FI->hasOneUse())) {
- // Intersect FMF from the fneg instructions and union those with the select.
- FastMathFlags FMF = TI->getFastMathFlags();
- FMF &= FI->getFastMathFlags();
- FMF |= SI.getFastMathFlags();
- Value *NewSel = Builder.CreateSelect(Cond, X, Y, SI.getName() + ".v", &SI);
- if (auto *NewSelI = dyn_cast<Instruction>(NewSel))
- NewSelI->setFastMathFlags(FMF);
- Instruction *NewFNeg = UnaryOperator::CreateFNeg(NewSel);
- NewFNeg->setFastMathFlags(FMF);
- return NewFNeg;
- }
-
- // Min/max intrinsic with a common operand can have the common operand pulled
- // after the select. This is the same transform as below for binops, but
- // specialized for intrinsic matching and without the restrictive uses clause.
- auto *TII = dyn_cast<IntrinsicInst>(TI);
- auto *FII = dyn_cast<IntrinsicInst>(FI);
- if (TII && FII && TII->getIntrinsicID() == FII->getIntrinsicID() &&
- (TII->hasOneUse() || FII->hasOneUse())) {
- Value *T0, *T1, *F0, *F1;
- if (match(TII, m_MaxOrMin(m_Value(T0), m_Value(T1))) &&
- match(FII, m_MaxOrMin(m_Value(F0), m_Value(F1)))) {
- if (T0 == F0) {
- Value *NewSel = Builder.CreateSelect(Cond, T1, F1, "minmaxop", &SI);
- return CallInst::Create(TII->getCalledFunction(), {NewSel, T0});
- }
- if (T0 == F1) {
- Value *NewSel = Builder.CreateSelect(Cond, T1, F0, "minmaxop", &SI);
- return CallInst::Create(TII->getCalledFunction(), {NewSel, T0});
- }
- if (T1 == F0) {
- Value *NewSel = Builder.CreateSelect(Cond, T0, F1, "minmaxop", &SI);
- return CallInst::Create(TII->getCalledFunction(), {NewSel, T1});
- }
- if (T1 == F1) {
- Value *NewSel = Builder.CreateSelect(Cond, T0, F0, "minmaxop", &SI);
- return CallInst::Create(TII->getCalledFunction(), {NewSel, T1});
+ Value *MatchOp, *OtherOpT, *OtherOpF;
+ bool MatchIsOpZero;
----------------
Possibly don't put MatchOp up here as it isn't touched by getCommonOp - use local 'MatchOp' variables for the places which call getCommonOp instead.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139075/new/
https://reviews.llvm.org/D139075
More information about the llvm-commits
mailing list