[llvm] 953cdcb - [InstCombine] early exit to reduce indents in foldSelectIntoOp(); NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 2 10:49:01 PST 2023
Author: Sanjay Patel
Date: 2023-01-02T13:33:27-05:00
New Revision: 953cdcb98956078d49c335cd57bf78af0d81dd01
URL: https://github.com/llvm/llvm-project/commit/953cdcb98956078d49c335cd57bf78af0d81dd01
DIFF: https://github.com/llvm/llvm-project/commit/953cdcb98956078d49c335cd57bf78af0d81dd01.diff
LOG: [InstCombine] early exit to reduce indents in foldSelectIntoOp(); NFC
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index ddf5882f901d..5ea30560093d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -466,44 +466,44 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
auto TryFoldSelectIntoOp = [&](SelectInst &SI, Value *TrueVal,
Value *FalseVal,
bool Swapped) -> Instruction * {
- if (auto *TVI = dyn_cast<BinaryOperator>(TrueVal)) {
- if (TVI->hasOneUse() && !isa<Constant>(FalseVal)) {
- if (unsigned SFO = getSelectFoldableOperands(TVI)) {
- unsigned OpToFold = 0;
- if ((SFO & 1) && FalseVal == TVI->getOperand(0))
- OpToFold = 1;
- else if ((SFO & 2) && FalseVal == TVI->getOperand(1))
- OpToFold = 2;
-
- if (OpToFold) {
- FastMathFlags FMF;
- // TODO: We probably ought to revisit cases where the select and FP
- // instructions have
diff erent flags and add tests to ensure the
- // behaviour is correct.
- if (isa<FPMathOperator>(&SI))
- FMF = SI.getFastMathFlags();
- Constant *C = ConstantExpr::getBinOpIdentity(
- TVI->getOpcode(), TVI->getType(), true, FMF.noSignedZeros());
- Value *OOp = TVI->getOperand(2 - OpToFold);
- // Avoid creating select between 2 constants unless it's selecting
- // between 0, 1 and -1.
- const APInt *OOpC;
- bool OOpIsAPInt = match(OOp, m_APInt(OOpC));
- if (!isa<Constant>(OOp) ||
- (OOpIsAPInt && isSelect01(C->getUniqueInteger(), *OOpC))) {
- Value *NewSel = Builder.CreateSelect(
- SI.getCondition(), Swapped ? C : OOp, Swapped ? OOp : C);
- if (isa<FPMathOperator>(&SI))
- cast<Instruction>(NewSel)->setFastMathFlags(FMF);
- NewSel->takeName(TVI);
- BinaryOperator *BO =
- BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel);
- BO->copyIRFlags(TVI);
- return BO;
- }
- }
- }
- }
+ auto *TVI = dyn_cast<BinaryOperator>(TrueVal);
+ if (!TVI || !TVI->hasOneUse() || isa<Constant>(FalseVal))
+ return nullptr;
+
+ unsigned SFO = getSelectFoldableOperands(TVI);
+ unsigned OpToFold = 0;
+ if ((SFO & 1) && FalseVal == TVI->getOperand(0))
+ OpToFold = 1;
+ else if ((SFO & 2) && FalseVal == TVI->getOperand(1))
+ OpToFold = 2;
+
+ if (!OpToFold)
+ return nullptr;
+
+ // TODO: We probably ought to revisit cases where the select and FP
+ // instructions have
diff erent flags and add tests to ensure the
+ // behaviour is correct.
+ FastMathFlags FMF;
+ if (isa<FPMathOperator>(&SI))
+ FMF = SI.getFastMathFlags();
+ Constant *C = ConstantExpr::getBinOpIdentity(
+ TVI->getOpcode(), TVI->getType(), true, FMF.noSignedZeros());
+ Value *OOp = TVI->getOperand(2 - OpToFold);
+ // Avoid creating select between 2 constants unless it's selecting
+ // between 0, 1 and -1.
+ const APInt *OOpC;
+ bool OOpIsAPInt = match(OOp, m_APInt(OOpC));
+ if (!isa<Constant>(OOp) ||
+ (OOpIsAPInt && isSelect01(C->getUniqueInteger(), *OOpC))) {
+ Value *NewSel = Builder.CreateSelect(SI.getCondition(), Swapped ? C : OOp,
+ Swapped ? OOp : C);
+ if (isa<FPMathOperator>(&SI))
+ cast<Instruction>(NewSel)->setFastMathFlags(FMF);
+ NewSel->takeName(TVI);
+ BinaryOperator *BO =
+ BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel);
+ BO->copyIRFlags(TVI);
+ return BO;
}
return nullptr;
};
More information about the llvm-commits
mailing list