forked from OSchip/llvm-project
[InstCombine] Preserve 'exact' in -(X >>u 31) -> (X >>s 31) fold
https://rise4fun.com/Alive/yR4 llvm-svn: 373363
This commit is contained in:
parent
f273fc793a
commit
65144149d0
|
@ -1676,12 +1676,16 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
|||
if (match(Op1, m_LShr(m_Value(X), m_APInt(ShAmt))) &&
|
||||
*ShAmt == BitWidth - 1) {
|
||||
Value *ShAmtOp = cast<Instruction>(Op1)->getOperand(1);
|
||||
return BinaryOperator::CreateAShr(X, ShAmtOp);
|
||||
Instruction *NewShift = BinaryOperator::CreateAShr(X, ShAmtOp);
|
||||
NewShift->copyIRFlags(Op1);
|
||||
return NewShift;
|
||||
}
|
||||
if (match(Op1, m_AShr(m_Value(X), m_APInt(ShAmt))) &&
|
||||
*ShAmt == BitWidth - 1) {
|
||||
Value *ShAmtOp = cast<Instruction>(Op1)->getOperand(1);
|
||||
return BinaryOperator::CreateLShr(X, ShAmtOp);
|
||||
Instruction *NewShift = BinaryOperator::CreateLShr(X, ShAmtOp);
|
||||
NewShift->copyIRFlags(Op1);
|
||||
return NewShift;
|
||||
}
|
||||
|
||||
if (Op1->hasOneUse()) {
|
||||
|
|
|
@ -12,7 +12,7 @@ define i64 @t0(i64 %x) {
|
|||
}
|
||||
define i64 @t0_exact(i64 %x) {
|
||||
; CHECK-LABEL: @t0_exact(
|
||||
; CHECK-NEXT: [[R:%.*]] = ashr i64 [[X:%.*]], 63
|
||||
; CHECK-NEXT: [[R:%.*]] = ashr exact i64 [[X:%.*]], 63
|
||||
; CHECK-NEXT: ret i64 [[R]]
|
||||
;
|
||||
%t0 = lshr exact i64 %x, 63
|
||||
|
@ -30,7 +30,7 @@ define i64 @t2(i64 %x) {
|
|||
}
|
||||
define i64 @t3_exact(i64 %x) {
|
||||
; CHECK-LABEL: @t3_exact(
|
||||
; CHECK-NEXT: [[R:%.*]] = lshr i64 [[X:%.*]], 63
|
||||
; CHECK-NEXT: [[R:%.*]] = lshr exact i64 [[X:%.*]], 63
|
||||
; CHECK-NEXT: ret i64 [[R]]
|
||||
;
|
||||
%t0 = ashr exact i64 %x, 63
|
||||
|
|
Loading…
Reference in New Issue