mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-26 09:18:56 +00:00
InstCombine: Don't miscompile (x lshr C1) udiv C2
We have a transform that changes: (x lshr C1) udiv C2 into: x udiv (C2 << C1) However, it is unsafe to do so if C2 << C1 discards any of C2's bits. This fixes PR21255. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219634 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2064,19 +2064,29 @@ APInt APInt::umul_ov(const APInt &RHS, bool &Overflow) const {
|
||||
return Res;
|
||||
}
|
||||
|
||||
APInt APInt::sshl_ov(unsigned ShAmt, bool &Overflow) const {
|
||||
Overflow = ShAmt >= getBitWidth();
|
||||
APInt APInt::sshl_ov(const APInt &ShAmt, bool &Overflow) const {
|
||||
Overflow = ShAmt.uge(getBitWidth());
|
||||
if (Overflow)
|
||||
ShAmt = getBitWidth()-1;
|
||||
return APInt(BitWidth, 0);
|
||||
|
||||
if (isNonNegative()) // Don't allow sign change.
|
||||
Overflow = ShAmt >= countLeadingZeros();
|
||||
Overflow = ShAmt.uge(countLeadingZeros());
|
||||
else
|
||||
Overflow = ShAmt >= countLeadingOnes();
|
||||
Overflow = ShAmt.uge(countLeadingOnes());
|
||||
|
||||
return *this << ShAmt;
|
||||
}
|
||||
|
||||
APInt APInt::ushl_ov(const APInt &ShAmt, bool &Overflow) const {
|
||||
Overflow = ShAmt.uge(getBitWidth());
|
||||
if (Overflow)
|
||||
return APInt(BitWidth, 0);
|
||||
|
||||
Overflow = ShAmt.ugt(countLeadingZeros());
|
||||
|
||||
return *this << ShAmt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user