Skip to content

Commit 11484cb

Browse files
committed
[InstCombine] Pass SimplifyQuery to SimplifyDemandedBits()
This will enable calling SimplifyDemandedBits() with a SimplifyQuery that has CondContext set in the future. Additionally this also marginally strengthens the analysis by retaining the original context instruction for one-use chains.
1 parent 7b2e16f commit 11484cb

File tree

6 files changed

+95
-86
lines changed

6 files changed

+95
-86
lines changed

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,14 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
504504

505505
virtual bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
506506
const APInt &DemandedMask, KnownBits &Known,
507-
unsigned Depth = 0) = 0;
507+
unsigned Depth, const SimplifyQuery &Q) = 0;
508+
509+
bool SimplifyDemandedBits(Instruction *I, unsigned OpNo,
510+
const APInt &DemandedMask, KnownBits &Known) {
511+
return SimplifyDemandedBits(I, OpNo, DemandedMask, Known,
512+
/*Depth=*/0, SQ.getWithInstruction(I));
513+
}
514+
508515
virtual Value *
509516
SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &UndefElts,
510517
unsigned Depth = 0,

llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ ARMTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
187187
}
188188
KnownBits ScalarKnown(32);
189189
if (IC.SimplifyDemandedBits(&II, 0, APInt::getLowBitsSet(32, 16),
190-
ScalarKnown, 0)) {
190+
ScalarKnown)) {
191191
return ⅈ
192192
}
193193
break;

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6451,13 +6451,13 @@ Instruction *InstCombinerImpl::foldICmpUsingKnownBits(ICmpInst &I) {
64516451
// Don't use dominating conditions when folding icmp using known bits. This
64526452
// may convert signed into unsigned predicates in ways that other passes
64536453
// (especially IndVarSimplify) may not be able to reliably undo.
6454-
SQ.DC = nullptr;
6455-
auto _ = make_scope_exit([&]() { SQ.DC = &DC; });
6454+
SimplifyQuery Q = SQ.getWithoutDomCondCache().getWithInstruction(&I);
64566455
if (SimplifyDemandedBits(&I, 0, getDemandedBitsLHSMask(I, BitWidth),
6457-
Op0Known, 0))
6456+
Op0Known, /*Depth=*/0, Q))
64586457
return &I;
64596458

6460-
if (SimplifyDemandedBits(&I, 1, APInt::getAllOnes(BitWidth), Op1Known, 0))
6459+
if (SimplifyDemandedBits(&I, 1, APInt::getAllOnes(BitWidth), Op1Known,
6460+
/*Depth=*/0, Q))
64616461
return &I;
64626462
}
64636463

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,18 +548,19 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
548548
/// Attempts to replace V with a simpler value based on the demanded
549549
/// bits.
550550
Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known,
551-
unsigned Depth, Instruction *CxtI);
551+
unsigned Depth, const SimplifyQuery &Q);
552+
using InstCombiner::SimplifyDemandedBits;
552553
bool SimplifyDemandedBits(Instruction *I, unsigned Op,
553554
const APInt &DemandedMask, KnownBits &Known,
554-
unsigned Depth = 0) override;
555+
unsigned Depth, const SimplifyQuery &Q) override;
555556

556557
/// Helper routine of SimplifyDemandedUseBits. It computes KnownZero/KnownOne
557558
/// bits. It also tries to handle simplifications that can be done based on
558559
/// DemandedMask, but without modifying the Instruction.
559560
Value *SimplifyMultipleUseDemandedBits(Instruction *I,
560561
const APInt &DemandedMask,
561-
KnownBits &Known,
562-
unsigned Depth, Instruction *CxtI);
562+
KnownBits &Known, unsigned Depth,
563+
const SimplifyQuery &Q);
563564

564565
/// Helper routine of SimplifyDemandedUseBits. It tries to simplify demanded
565566
/// bit for "r1 = shr x, c1; r2 = shl r1, c2" instruction sequence.

0 commit comments

Comments
 (0)