mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-28 00:40:54 +00:00
Fix PR16360
When (srl (anyextend x), c) is folded into (anyextend (srl x, c)), the high bits are not cleared. Add 'and' to clear off them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184575 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c12c880998
commit
2da863984b
@ -3915,8 +3915,7 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
|
|||||||
DAG.getConstant(~0ULL >> ShAmt, VT));
|
DAG.getConstant(~0ULL >> ShAmt, VT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fold (srl (anyextend x), c) -> (and (anyextend (srl x, c)), mask)
|
||||||
// fold (srl (anyextend x), c) -> (anyextend (srl x, c))
|
|
||||||
if (N1C && N0.getOpcode() == ISD::ANY_EXTEND) {
|
if (N1C && N0.getOpcode() == ISD::ANY_EXTEND) {
|
||||||
// Shifting in all undef bits?
|
// Shifting in all undef bits?
|
||||||
EVT SmallVT = N0.getOperand(0).getValueType();
|
EVT SmallVT = N0.getOperand(0).getValueType();
|
||||||
@ -3929,7 +3928,10 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
|
|||||||
N0.getOperand(0),
|
N0.getOperand(0),
|
||||||
DAG.getConstant(ShiftAmt, getShiftAmountTy(SmallVT)));
|
DAG.getConstant(ShiftAmt, getShiftAmountTy(SmallVT)));
|
||||||
AddToWorkList(SmallShift.getNode());
|
AddToWorkList(SmallShift.getNode());
|
||||||
return DAG.getNode(ISD::ANY_EXTEND, SDLoc(N), VT, SmallShift);
|
APInt Mask = APInt::getAllOnesValue(VT.getSizeInBits()).lshr(ShiftAmt);
|
||||||
|
return DAG.getNode(ISD::AND, SDLoc(N), VT,
|
||||||
|
DAG.getNode(ISD::ANY_EXTEND, SDLoc(N), VT, SmallShift),
|
||||||
|
DAG.getConstant(Mask, VT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
test/CodeGen/X86/pr16360.ll
Normal file
16
test/CodeGen/X86/pr16360.ll
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
; RUN: llc < %s -mtriple=i686-pc-linux | FileCheck %s
|
||||||
|
|
||||||
|
define i64 @foo(i32 %sum) {
|
||||||
|
entry:
|
||||||
|
%conv = sext i32 %sum to i64
|
||||||
|
%shr = lshr i64 %conv, 2
|
||||||
|
%or = or i64 4611686018360279040, %shr
|
||||||
|
ret i64 %or
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK: foo
|
||||||
|
; CHECK: shrl $2
|
||||||
|
; CHECK: orl $-67108864
|
||||||
|
; CHECK-NOT: movl $-1
|
||||||
|
; CHECK: movl $1073741823
|
||||||
|
; CHECK: ret
|
Loading…
x
Reference in New Issue
Block a user