[llvm-bugs] [Bug 27974] New: nounroll attribute is sometimes lost after optimizations

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 1 15:36:37 PDT 2016


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

            Bug ID: 27974
           Summary: nounroll attribute is sometimes lost after
                    optimizations
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: justin.lebar at gmail.com
                CC: llvm-bugs at lists.llvm.org,
                    sanjoy at playingwithpointers.com
    Classification: Unclassified

The NVPTX backend relies on the nounroll attribute not being stripped by
optimizations.  Its assembly printer detects nounroll loops and emits an asm
directive to ptxas telling it not to unroll loops, where appropriate.

The attached unoptimized IR has a few loops marked as nounroll.  After
optimization, most of the nounroll loops are still present; however, the
nounroll loops inside the /.*RowReduce.*/ functions are gone.

Unoptimized IR: https://gist.github.com/e6e8822a01dde1bb20195b4002d8efc3
Optimized IR (opt -O3):
https://gist.github.com/d8fa9ec0295e4ae808a8150e776b6871

Specifically, the function
_ZN5Eigen8internal12_GLOBAL__N_115RowReduceKernelILi32ELi256ELi128ENS_15TensorEvaluatorIKNS_9TensorMapINS_6TensorIfLi2ELi1EiEELi0EEENS_9GpuDeviceEEENS0_10PtrWrapperIfiEENS1_14CudaMaxReducerEEEvT4_T2_iiT3_
in the unoptimized IR has four branches with llvm.loop annotations:

  br label %121, !llvm.loop !57
  br label %158, !llvm.loop !58
  br label %104, !llvm.loop !59
  br label %197, !llvm.loop !60

The annotations are defined as

  !49 = !{!"llvm.loop.unroll.enable"}
  !55 = !{!"llvm.loop.unroll.disable"}
  !57 = distinct !{!57, !49}
  !58 = distinct !{!58, !49}
  !59 = distinct !{!59, !55}
  !60 = distinct !{!60, !49}

But after optimization, the same function has only one annotated branch:

  br i1 %182, label %178, label %.thread, !llvm.loop !59

  !55 = !{!"llvm.loop.unroll.enable"}
  !59 = distinct !{!59, !55}

(This is a loop which cannot be unrolled, because it contains volatile inline
asm.)

Based on the C++ source code, I am pretty sure that the backedge in the
optimized code that ought to have retained the llvm.loop.unroll.disable
attribute is

  br i1 %164, label %48, label %.thread.preheader.loopexit.

-- 
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/20160601/861fe8bb/attachment.html>


More information about the llvm-bugs mailing list