Skip to content

Commit 7a2dc67

Browse files
committed
moved calls to consistent location in each visit function + added call to visitAnd
1 parent 4c86e54 commit 7a2dc67

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,18 @@ static Value *foldThreeVarBoolExpr(Value *Root,
252252
if (!isa<BinaryOperator>(Root))
253253
return nullptr;
254254

255+
// Early bailout for expressions with too many uses (avoid expensive analysis
256+
// andorxor.ll)
257+
if (!Root->hasOneUse())
258+
return nullptr;
259+
255260
// Skip transformation if expression is already simple (at most 2 levels
256261
// deep).
257-
if (Root->hasOneUse() && isa<BinaryOperator>(Root)) {
258-
if (auto *BO = dyn_cast<BinaryOperator>(Root)) {
259-
bool IsSimple = !isa<BinaryOperator>(BO->getOperand(0)) ||
260-
!isa<BinaryOperator>(BO->getOperand(1));
261-
if (IsSimple)
262-
return nullptr;
263-
}
262+
if (auto *BO = dyn_cast<BinaryOperator>(Root)) {
263+
bool IsSimple = !isa<BinaryOperator>(BO->getOperand(0)) ||
264+
!isa<BinaryOperator>(BO->getOperand(1));
265+
if (IsSimple)
266+
return nullptr;
264267
}
265268

266269
auto [Op0, Op1, Op2] = extractThreeVariables(Root);
@@ -271,10 +274,6 @@ static Value *foldThreeVarBoolExpr(Value *Root,
271274
if (!Table)
272275
return nullptr;
273276

274-
// Only transform expressions with single use to avoid code growth.
275-
if (!Root->hasOneUse())
276-
return nullptr;
277-
278277
return createLogicFromTable3Var(*Table, Op0, Op1, Op2, Root, Builder, true);
279278
}
280279

@@ -2628,6 +2627,9 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
26282627
if (Instruction *Phi = foldBinopWithPhiOperands(I))
26292628
return Phi;
26302629

2630+
if (Value *Canonical = foldThreeVarBoolExpr(&I, Builder))
2631+
return replaceInstUsesWith(I, Canonical);
2632+
26312633
// See if we can simplify any instructions used by the instruction whose sole
26322634
// purpose is to compute bits we don't care about.
26332635
if (SimplifyDemandedInstructionBits(I))
@@ -3985,6 +3987,9 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
39853987
if (Instruction *Phi = foldBinopWithPhiOperands(I))
39863988
return Phi;
39873989

3990+
if (Value *Canonical = foldThreeVarBoolExpr(&I, Builder))
3991+
return replaceInstUsesWith(I, Canonical);
3992+
39883993
// See if we can simplify any instructions used by the instruction whose sole
39893994
// purpose is to compute bits we don't care about.
39903995
if (SimplifyDemandedInstructionBits(I))
@@ -4008,9 +4013,6 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
40084013

40094014
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
40104015

4011-
if (Value *Canonical = foldThreeVarBoolExpr(&I, Builder))
4012-
return replaceInstUsesWith(I, Canonical);
4013-
40144016
Type *Ty = I.getType();
40154017
if (Ty->isIntOrIntVectorTy(1)) {
40164018
if (auto *SI0 = dyn_cast<SelectInst>(Op0)) {
@@ -5136,6 +5138,9 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
51365138
if (Instruction *Phi = foldBinopWithPhiOperands(I))
51375139
return Phi;
51385140

5141+
if (Value *Canonical = foldThreeVarBoolExpr(&I, Builder))
5142+
return replaceInstUsesWith(I, Canonical);
5143+
51395144
if (Instruction *NewXor = foldXorToXor(I, Builder))
51405145
return NewXor;
51415146

@@ -5417,9 +5422,6 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
54175422
}
54185423
}
54195424

5420-
if (Value *Canonical = foldThreeVarBoolExpr(&I, Builder))
5421-
return replaceInstUsesWith(I, Canonical);
5422-
54235425
if (auto *LHS = dyn_cast<ICmpInst>(I.getOperand(0)))
54245426
if (auto *RHS = dyn_cast<ICmpInst>(I.getOperand(1)))
54255427
if (Value *V = foldXorOfICmps(LHS, RHS, I))

0 commit comments

Comments
 (0)