Skip to content

Commit cbbbd5b

Browse files
committed
[GlobalISel] Make use of KnownBits::computeForAddSub
Summary: This is mostly NFC. computeForAddSub may give more precise results in some cases, but that doesn't seem to affect any existing GlobalISel tests. Subscribers: rovka, hiraditya, volkan, Petar.Avramovic, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73431
1 parent 6fb3d59 commit cbbbd5b

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,12 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
169169
break;
170170
}
171171
case TargetOpcode::G_SUB: {
172-
// If low bits are known to be zero in both operands, then we know they are
173-
// going to be 0 in the result. Both addition and complement operations
174-
// preserve the low zero bits.
175-
computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
172+
computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
176173
Depth + 1);
177-
unsigned KnownZeroLow = Known2.countMinTrailingZeros();
178-
if (KnownZeroLow == 0)
179-
break;
180174
computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
181175
Depth + 1);
182-
KnownZeroLow = std::min(KnownZeroLow, Known2.countMinTrailingZeros());
183-
Known.Zero.setLowBits(KnownZeroLow);
176+
Known = KnownBits::computeForAddSub(/*Add*/ false, /*NSW*/ false, Known,
177+
Known2);
184178
break;
185179
}
186180
case TargetOpcode::G_XOR: {
@@ -204,24 +198,12 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
204198
LLVM_FALLTHROUGH;
205199
}
206200
case TargetOpcode::G_ADD: {
207-
// Output known-0 bits are known if clear or set in both the low clear bits
208-
// common to both LHS & RHS. For example, 8+(X<<3) is known to have the
209-
// low 3 bits clear.
210-
// Output known-0 bits are also known if the top bits of each input are
211-
// known to be clear. For example, if one input has the top 10 bits clear
212-
// and the other has the top 8 bits clear, we know the top 7 bits of the
213-
// output must be clear.
214-
computeKnownBitsImpl(MI.getOperand(1).getReg(), Known2, DemandedElts,
201+
computeKnownBitsImpl(MI.getOperand(1).getReg(), Known, DemandedElts,
215202
Depth + 1);
216-
unsigned KnownZeroHigh = Known2.countMinLeadingZeros();
217-
unsigned KnownZeroLow = Known2.countMinTrailingZeros();
218203
computeKnownBitsImpl(MI.getOperand(2).getReg(), Known2, DemandedElts,
219204
Depth + 1);
220-
KnownZeroHigh = std::min(KnownZeroHigh, Known2.countMinLeadingZeros());
221-
KnownZeroLow = std::min(KnownZeroLow, Known2.countMinTrailingZeros());
222-
Known.Zero.setLowBits(KnownZeroLow);
223-
if (KnownZeroHigh > 1)
224-
Known.Zero.setHighBits(KnownZeroHigh - 1);
205+
Known =
206+
KnownBits::computeForAddSub(/*Add*/ true, /*NSW*/ false, Known, Known2);
225207
break;
226208
}
227209
case TargetOpcode::G_AND: {

0 commit comments

Comments
 (0)