diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-04-01 19:01:09 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-04-01 19:01:09 +0000 |
| commit | 3a16a36bb6e05c04a0550d1e01e72e99599fcbc2 (patch) | |
| tree | fe87bcc65bdd177eff0ebf903bec388a4b177faf /llvm | |
| parent | 029838496f43a03ddf4028be0468cc8ac194f917 (diff) | |
| download | bcm5719-llvm-3a16a36bb6e05c04a0550d1e01e72e99599fcbc2.tar.gz bcm5719-llvm-3a16a36bb6e05c04a0550d1e01e72e99599fcbc2.zip | |
[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.
llvm-svn: 233832
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/CodeGen/X86/narrow-shl-cst.ll | 23 |
2 files changed, 29 insertions, 1 deletions
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp index fb12ce51db2..5da7acfc6ef 100644 --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -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)); } diff --git a/llvm/test/CodeGen/X86/narrow-shl-cst.ll b/llvm/test/CodeGen/X86/narrow-shl-cst.ll index 40b976014a7..c9e9a3d2a97 100644 --- a/llvm/test/CodeGen/X86/narrow-shl-cst.ll +++ b/llvm/test/CodeGen/X86/narrow-shl-cst.ll @@ -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 +} |

