[PATCH] D37896: [DAGCombine] Resolving PR34474 by transforming mul(x, 2^c +/- 1) -> sub/add(shl(x, c) x) for any type including vector types

Michael Haidl via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 15 05:32:40 PST 2018


pacxx added a comment.

I enabled this opt for scalar values as sugested and have now additional 60 tests failing. The problem is, that for scalar values, this optimization does not only affect multiplication instructions but also address calculations. E.g., `test/CodeGen/AArch64/machine-combiner-madd.ll` fails because for the tested indexing in a load a `madd` instruction is expected but this optimization is not performed on the new generated instruction pattern which includes now a left shift and a subtraction.

Another problem is that this optimization on scalar values seems to hinder target specific optimizations like:

  16 define i32 @test3(i32 %x) {
  17 ; CHECK-LABEL: test3
  18 ; CHECK: add w0, w0, w0, lsl #1
  19
  20   %mul = mul nsw i32 %x, 3
  21   ret i32 %mul
  22 }

in `CodeGen/AArch64/mul_pow2.ll` which will now generate also a left shift subtraction pattern instead of the expected add with 3 arguments. Since this goes far beyond the scope of this transformation I would suggest to let this optimization disabled for scalar values because I cannot estimate the impact and possible regressions arising from this optimization for all (11) affected targets.


https://reviews.llvm.org/D37896





More information about the llvm-commits mailing list