[llvm-bugs] [Bug 31368] New: [Scalar] alignTo is not optimized if alignment is a power of 2

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 13 19:30:10 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31368

            Bug ID: 31368
           Summary: [Scalar] alignTo is not optimized if alignment is a
                    power of 2
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: davide at freebsd.org
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

This came up as part of https://reviews.llvm.org/D27082
Testcase by Rafael.

uint64_t foo(uint64_t Value, uint64_t Align) {
  return alignToNonP2(Value, 1 << Align);
}

but it still produces

define i64 @_Z3foomm(i64 %Value, i64 %Align) local_unnamed_addr #0 {
entry:
  %sh_prom = trunc i64 %Align to i32
  %shl = shl i32 1, %sh_prom
  %conv = sext i32 %shl to i64
  %add.i = add i64 %Value, -1
  %sub.i = add i64 %add.i, %conv
  %div.i = urem i64 %sub.i, %conv
  %add2.i = sub i64 %sub.i, %div.i
  ret i64 %add2.i
}

Changing 1 to 1ULL does cause us to optimize it

define i64 @_Z3foomm(i64 %Value, i64 %Align) local_unnamed_addr #0 {
entry:
  %shl = shl i64 1, %Align
  %add.i = add i64 %Value, -1
  %sub.i = add i64 %add.i, %shl
  %.not = sub i64 0, %shl
  %add2.i = and i64 %sub.i, %.not
  ret i64 %add2.i
}

-- 
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/20161214/7637f72d/attachment.html>


More information about the llvm-bugs mailing list