Emit a more efficient magic number multiplication for exact sdivs.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 8 Jul 2011 10:31:30 +0000 (10:31 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 8 Jul 2011 10:31:30 +0000 (10:31 +0000)
commit9c64030445cbe6ac486b90c5f459f91e06770474
tree54fd00aa621f35212da8d6fd83e840288382771f
parentebdeeab812beec0385b445f3d4c41a114e0d972f
Emit a more efficient magic number multiplication for exact sdivs.

We have to do this in DAGBuilder instead of DAGCombiner, because the exact bit is lost after building.

  struct foo { char x[24]; };
  long bar(struct foo *a, struct foo *b) { return a-b; }
is now compiled into
  movl 4(%esp), %eax
  subl 8(%esp), %eax
  sarl $3, %eax
  imull $-1431655765, %eax, %eax
instead of
  movl 4(%esp), %eax
  subl 8(%esp), %eax
  movl $715827883, %ecx
  imull %ecx
  movl %edx, %eax
  shrl $31, %eax
  sarl $2, %edx
  addl %eax, %edx
  movl %edx, %eax

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134695 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Target/TargetLowering.h
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
lib/CodeGen/SelectionDAG/TargetLowering.cpp
test/CodeGen/X86/sdiv-exact.ll [new file with mode: 0644]