Go to file
David Majnemer f9a095d606 InstCombine: Combine mul with div.
We can combne a mul with a div if one of the operands is a multiple of
the other:

%mul = mul nsw nuw %a, C1
%ret = udiv %mul, C2
  =>
%ret = mul nsw %a, (C1 / C2)

This can expose further optimization opportunities if we end up
multiplying or dividing by a power of 2.

Consider this small example:

define i32 @f(i32 %a) {
  %mul = mul nuw i32 %a, 14
  %div = udiv exact i32 %mul, 7
  ret i32 %div
}

which gets CodeGen'd to:

    imull       $14, %edi, %eax
    imulq       $613566757, %rax, %rcx
    shrq        $32, %rcx
    subl        %ecx, %eax
    shrl        %eax
    addl        %ecx, %eax
    shrl        $2, %eax
    retq

We can now transform this into:
define i32 @f(i32 %a) {
  %shl = shl nuw i32 %a, 1
  ret i32 %shl
}

which gets CodeGen'd to:

    leal        (%rdi,%rdi), %eax
    retq

This fixes PR20681.

llvm-svn: 215815
2014-08-16 08:55:06 +00:00
clang Uniformed parsing of GNU attributes at line beginnning and added GNU attributes parsing FIXMEs. 2014-08-16 08:29:27 +00:00
clang-tools-extra AvoidCStyleCastsCheck: don't warn on casts in macros 2014-08-16 00:53:20 +00:00
compiler-rt [TSan] Initialize flags as early as possible. Disables back coredump, accidentally enabled in r215479. Add a test. 2014-08-15 19:53:51 +00:00
debuginfo-tests relax testcase for LLDB output format compatibility. 2014-03-19 23:06:18 +00:00
libclc relational: Add islessequal(floatN) builtin 2014-08-01 21:50:59 +00:00
libcxx [libcxx] Update the way the -std= flag is chosen by CMake and LibcxxTestFormat 2014-08-16 01:35:36 +00:00
libcxxabi Fix the CMake build on Mac when setting MACOSX_DEPLOYMENT_TARGET=10.6 2014-08-12 18:18:07 +00:00
lld [mach-o] improve darwin driver 'usage' message when run with no args 2014-08-15 22:42:46 +00:00
lldb Enable the data formatter for std::vector<bool> on libc++ again. In recent clang builds, we are vended a different typename, which the formatter needs to match against. 2014-08-16 01:02:36 +00:00
llvm InstCombine: Combine mul with div. 2014-08-16 08:55:06 +00:00
openmp Commit PowerPC64 support from Carlo Bertolli at IBM. 2014-08-07 10:12:54 +00:00
polly Added support for modulo expressions 2014-08-15 01:14:11 +00:00