[llvm] 44fd457 - [SimplifyCFG] Extract helper for creating logical op (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue May 4 10:51:45 PDT 2021
Author: Nikita Popov
Date: 2021-05-04T19:51:30+02:00
New Revision: 44fd4575b39a14f98f6c3ace91795bd75e14732c
URL: https://github.com/llvm/llvm-project/commit/44fd4575b39a14f98f6c3ace91795bd75e14732c
DIFF: https://github.com/llvm/llvm-project/commit/44fd4575b39a14f98f6c3ace91795bd75e14732c.diff
LOG: [SimplifyCFG] Extract helper for creating logical op (NFC)
Added:
Modified:
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 836ab432271e..ebbc63b6f6cb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2959,6 +2959,19 @@ bool SimplifyCFGOpt::SimplifyCondBranchToTwoReturns(BranchInst *BI,
return true;
}
+static Value *createLogicalOp(IRBuilderBase &Builder,
+ Instruction::BinaryOps Opc, Value *LHS,
+ Value *RHS, const Twine &Name = "") {
+ // Try to relax logical op to binary op.
+ if (impliesPoison(RHS, LHS))
+ return Builder.CreateBinOp(Opc, LHS, RHS, Name);
+ if (Opc == Instruction::And)
+ return Builder.CreateLogicalAnd(LHS, RHS, Name);
+ if (Opc == Instruction::Or)
+ return Builder.CreateLogicalOr(LHS, RHS, Name);
+ llvm_unreachable("Invalid logical opcode");
+}
+
/// Return true if either PBI or BI has branch weight available, and store
/// the weights in {Pred|Succ}{True|False}Weight. If one of PBI and BI does
/// not have branch weight, use 1:1 as its weight.
@@ -3126,17 +3139,9 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
// Now that the Cond was cloned into the predecessor basic block,
// or/and the two conditions together.
- Value *NewCond = nullptr;
Value *BICond = VMap[BI->getCondition()];
-
- if (impliesPoison(BICond, PBI->getCondition()))
- NewCond = Builder.CreateBinOp(Opc, PBI->getCondition(), BICond, "or.cond");
- else
- NewCond =
- Opc == Instruction::And
- ? Builder.CreateLogicalAnd(PBI->getCondition(), BICond, "or.cond")
- : Builder.CreateLogicalOr(PBI->getCondition(), BICond, "or.cond");
- PBI->setCondition(NewCond);
+ PBI->setCondition(
+ createLogicalOp(Builder, Opc, PBI->getCondition(), BICond, "or.cond"));
// Copy any debug value intrinsics into the end of PredBlock.
for (Instruction &I : *BB) {
More information about the llvm-commits
mailing list