mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 04:33:05 +00:00
[X86] Don't accidentally select shll $1, %eax when shrinking an immediate.
addl has higher throughput and this was needlessly picking a suboptimal encoding causing PR23098. I wish there was a way of doing this without further duplicating tbl- generated patterns, but so far I haven't found one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233832 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5436372079
commit
a066ed09db
@ -2187,7 +2187,7 @@ SDNode *X86DAGToDAGISel::Select(SDNode *Node) {
|
||||
if (Opcode != ISD::AND && (Val & RemovedBitsMask) != 0)
|
||||
break;
|
||||
|
||||
unsigned ShlOp, Op;
|
||||
unsigned ShlOp, AddOp, Op;
|
||||
MVT CstVT = NVT;
|
||||
|
||||
// Check the minimum bitwidth for the new constant.
|
||||
@ -2208,6 +2208,7 @@ SDNode *X86DAGToDAGISel::Select(SDNode *Node) {
|
||||
case MVT::i32:
|
||||
assert(CstVT == MVT::i8);
|
||||
ShlOp = X86::SHL32ri;
|
||||
AddOp = X86::ADD32rr;
|
||||
|
||||
switch (Opcode) {
|
||||
default: llvm_unreachable("Impossible opcode");
|
||||
@ -2219,6 +2220,7 @@ SDNode *X86DAGToDAGISel::Select(SDNode *Node) {
|
||||
case MVT::i64:
|
||||
assert(CstVT == MVT::i8 || CstVT == MVT::i32);
|
||||
ShlOp = X86::SHL64ri;
|
||||
AddOp = X86::ADD64rr;
|
||||
|
||||
switch (Opcode) {
|
||||
default: llvm_unreachable("Impossible opcode");
|
||||
@ -2232,6 +2234,9 @@ SDNode *X86DAGToDAGISel::Select(SDNode *Node) {
|
||||
// Emit the smaller op and the shift.
|
||||
SDValue NewCst = CurDAG->getTargetConstant(Val >> ShlVal, CstVT);
|
||||
SDNode *New = CurDAG->getMachineNode(Op, dl, NVT, N0->getOperand(0),NewCst);
|
||||
if (ShlVal == 1)
|
||||
return CurDAG->SelectNodeTo(Node, AddOp, NVT, SDValue(New, 0),
|
||||
SDValue(New, 0));
|
||||
return CurDAG->SelectNodeTo(Node, ShlOp, NVT, SDValue(New, 0),
|
||||
getI8Imm(ShlVal));
|
||||
}
|
||||
|
@ -99,3 +99,26 @@ define i64 @test11(i64 %x) nounwind {
|
||||
; CHECK: xorq $-65536
|
||||
; CHECK: shlq $33
|
||||
}
|
||||
|
||||
; PR23098
|
||||
define i32 @test12(i32 %x, i32* %y) nounwind {
|
||||
%and = shl i32 %x, 1
|
||||
%shl = and i32 %and, 255
|
||||
store i32 %shl, i32* %y
|
||||
ret i32 %shl
|
||||
; CHECK-LABEL: test12:
|
||||
; CHECK: andl $127
|
||||
; CHECK-NEXT: addl
|
||||
; CHECK-NOT: shl
|
||||
}
|
||||
|
||||
define i64 @test13(i64 %x, i64* %y) nounwind {
|
||||
%and = shl i64 %x, 1
|
||||
%shl = and i64 %and, 255
|
||||
store i64 %shl, i64* %y
|
||||
ret i64 %shl
|
||||
; CHECK-LABEL: test13:
|
||||
; CHECK: andq $127
|
||||
; CHECK-NEXT: addq
|
||||
; CHECK-NOT: shl
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user