Skip to content

Commit d0e87a7

Browse files
committed
fixup! Address review comments.
1 parent 0027fc3 commit d0e87a7

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ class BinaryOperator : public Instruction {
336336
return BO;
337337
}
338338

339+
static inline BinaryOperator *
340+
CreateDisjoint(BinaryOps Opc, Value *V1, Value *V2, const Twine &Name = "");
341+
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
342+
Value *V2, const Twine &Name,
343+
BasicBlock *BB);
344+
static inline BinaryOperator *CreateDisjoint(BinaryOps Opc, Value *V1,
345+
Value *V2, const Twine &Name,
346+
Instruction *I);
339347
#define DEFINE_HELPERS(OPC, NUWNSWEXACT) \
340348
static BinaryOperator *Create##NUWNSWEXACT##OPC(Value *V1, Value *V2, \
341349
const Twine &Name = "") { \
@@ -364,6 +372,8 @@ class BinaryOperator : public Instruction {
364372
DEFINE_HELPERS(AShr, Exact) // CreateExactAShr
365373
DEFINE_HELPERS(LShr, Exact) // CreateExactLShr
366374

375+
DEFINE_HELPERS(Or, Disjoint) // CreateDisjointOr
376+
367377
#undef DEFINE_HELPERS
368378

369379
/// Helper functions to construct and inspect unary operations (NEG and NOT)
@@ -438,6 +448,27 @@ class PossiblyDisjointInst : public BinaryOperator {
438448
}
439449
};
440450

451+
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
452+
Value *V2, const Twine &Name) {
453+
BinaryOperator *BO = Create(Opc, V1, V2, Name);
454+
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
455+
return BO;
456+
}
457+
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
458+
Value *V2, const Twine &Name,
459+
BasicBlock *BB) {
460+
BinaryOperator *BO = Create(Opc, V1, V2, Name, BB);
461+
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
462+
return BO;
463+
}
464+
BinaryOperator *BinaryOperator::CreateDisjoint(BinaryOps Opc, Value *V1,
465+
Value *V2, const Twine &Name,
466+
Instruction *I) {
467+
BinaryOperator *BO = Create(Opc, V1, V2, Name, I);
468+
cast<PossiblyDisjointInst>(BO)->setIsDisjoint(true);
469+
return BO;
470+
}
471+
441472
//===----------------------------------------------------------------------===//
442473
// CastInst Class
443474
//===----------------------------------------------------------------------===//

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,11 +1582,8 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
15821582

15831583
// A+B --> A|B iff A and B have no bits set in common.
15841584
WithCache<const Value *> LHSCache(LHS), RHSCache(RHS);
1585-
if (haveNoCommonBitsSet(LHSCache, RHSCache, SQ.getWithInstruction(&I))) {
1586-
auto *Or = BinaryOperator::CreateOr(LHS, RHS);
1587-
cast<PossiblyDisjointInst>(Or)->setIsDisjoint(true);
1588-
return Or;
1589-
}
1585+
if (haveNoCommonBitsSet(LHSCache, RHSCache, SQ.getWithInstruction(&I)))
1586+
return BinaryOperator::CreateDisjointOr(LHS, RHS);
15901587

15911588
if (Instruction *Ext = narrowMathIfNoOverflow(I))
15921589
return Ext;

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,9 +4463,7 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
44634463
Value *M;
44644464
if (match(&I, m_c_Xor(m_c_And(m_Not(m_Value(M)), m_Value()),
44654465
m_c_And(m_Deferred(M), m_Value())))) {
4466-
auto *Or = BinaryOperator::CreateOr(Op0, Op1);
4467-
cast<PossiblyDisjointInst>(Or)->setIsDisjoint(true);
4468-
return Or;
4466+
return BinaryOperator::CreateDisjointOr(Op0, Op1);
44694467
}
44704468

44714469
if (Instruction *Xor = visitMaskedMerge(I, Builder))

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
315315
if (DemandedMask.isSubsetOf(RHSKnown.Zero | LHSKnown.Zero)) {
316316
Instruction *Or =
317317
BinaryOperator::CreateOr(I->getOperand(0), I->getOperand(1));
318-
cast<PossiblyDisjointInst>(Or)->setIsDisjoint(true);
318+
if (DemandedMask.isAllOnes())
319+
cast<PossiblyDisjointInst>(Or)->setIsDisjoint(true);
319320
Or->takeName(I);
320321
return InsertNewInstWith(Or, I->getIterator());
321322
}

0 commit comments

Comments
 (0)