[PATCH] D26605: [DAGCombiner] Fix infinite loop in vector mul/shl combining

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 06:08:04 PST 2016


john.brawn created this revision.
john.brawn added reviewers: RKSimon, bogner, spatel.
john.brawn added a subscriber: llvm-commits.
john.brawn set the repository for this revision to rL LLVM.

We have the following DAGCombiner transformations:

  (mul (shl X, c1), c2) -> (mul X, c2 << c1)
  (mul (shl X, C), Y) -> (shl (mul X, Y), C)
  (shl (mul x, c1), c2) -> (mul x, c1 << c2)

Usually the constant shift is optimised by SelectionDAG::getNode when it is constructed, by SelectionDAG::FoldConstantArithmetic, but when we're dealing with vectors and one of those vector constants contains an undef element FoldConstantArithmetic does not fold and we enter an infinite loop.

Fix this by making FoldConstantArithmetic fold undef+x into undef, the same as FoldConstantVectorArithmetic does, and instead of adding the constant shift to the work list assert that it's already been folded into a constant, as if it's not we're going to loop endlessly. Additionally add missing NoOpaques to one of those transformations, which I noticed when writing the tests for this.


Repository:
  rL LLVM

https://reviews.llvm.org/D26605

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  test/CodeGen/AArch64/dag-combine-mul-shl.ll
  test/CodeGen/X86/legalize-shl-vec.ll
  test/CodeGen/X86/merge-consecutive-loads-128.ll
  test/CodeGen/X86/shift-pcmp.ll
  test/CodeGen/X86/widen_load-2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26605.77796.patch
Type: text/x-patch
Size: 12237 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161114/afd602ab/attachment.bin>


More information about the llvm-commits mailing list