[LLVMbugs] [Bug 20905] New: instcombine does not preserve min pattern

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Sep 11 00:41:34 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20905

            Bug ID: 20905
           Summary: instcombine does not preserve min pattern
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: zvi.rackover at intel.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

For the following function:

define i32 @min_test(i32 %A, i32 %B) {
bb:
  %tmp27 = mul nsw i32 1904000, %B
  %tmp29 = mul nsw i32 2609823, %A
  %tmp30 = add nsw i32 %tmp27, %tmp29
  %tmp31 = sub nsw i32 %tmp30, 363703744
  %tmp32 = sdiv i32 %tmp31, 1635200
  %tmp50 = icmp sge i32 %tmp32, 0
  %tmp51 = select i1 %tmp50, i32 %tmp32, i32 0
  ret i32 %tmp51
}

After InstCombine we get:

define i32 @min_test(i32 %A, i32 %B) {
bb:
  %tmp27 = mul nsw i32 %B, 1904000
  %tmp29 = mul nsw i32 %A, 2609823
  %tmp30 = add nsw i32 %tmp27, %tmp29
  %tmp31 = add nsw i32 %tmp30, -363703744
  %tmp32 = sdiv i32 %tmp31, 1635200
  %tmp50 = icmp sgt i32 %tmp31, -1635200
  %tmp51 = select i1 %tmp50, i32 %tmp32, i32 0
  ret i32 %tmp51
}

After the transformation, the second 'icmp' operand and the third 'select'
operand do not match, and the min pattern will not be identified by Instruction
Selection, for example.

I found the following comment in InstCombine, indicating that the above
transformation is not desirable.
// Test if the ICmpInst instruction is used exclusively by a select as
// part of a minimum or maximum operation. If so, refrain from doing
// any other folding. This helps out other analyses which understand
// non-obfuscated minimum and maximum idioms, such as ScalarEvolution
// and CodeGen. And in this case, at least one of the comparison
// operands has at least one user besides the compare (the select),
// which would often largely negate the benefit of folding anyway.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140911/d595f6ad/attachment.html>


More information about the llvm-bugs mailing list