[llvm-bugs] [Bug 52173] New: [polly] buildFADOutermostDimensionLoad - suspicious unused sub

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 14 02:24:31 PDT 2021


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

            Bug ID: 52173
           Summary: [polly] buildFADOutermostDimensionLoad - suspicious
                    unused sub
           Product: Polly
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: isl
          Assignee: polly-dev at googlegroups.com
          Reporter: llvm-dev at redking.me.uk
                CC: llvm-bugs at lists.llvm.org, llvm at meinersbur.de,
                    siddharth.bhat at research.iiit.ac.in

This was reported as a dead code warning on coverity:

/// Generate the computation of the size of the outermost dimension from the
/// Fortran array descriptor (in this case, `@g_arr`). The final `%size`
/// contains the size of the array.
///
/// %arrty = type { i8*, i64, i64, [3 x %desc.dimensionty] }
/// %desc.dimensionty = type { i64, i64, i64 }
/// @g_arr = global %arrty zeroinitializer, align 32
/// ...
/// %0 = load i64, i64* getelementptr inbounds
///                       (%arrty, %arrty* @g_arr, i64 0, i32 3, i64 0, i32 2)
/// %1 = load i64, i64* getelementptr inbounds
///                      (%arrty, %arrty* @g_arr, i64 0, i32 3, i64 0, i32 1)
/// %2 = sub nsw i64 %0, %1
/// %size = add nsw i64 %2, 1
static Value *buildFADOutermostDimensionLoad(Value *GlobalDescriptor,
                                             PollyIRBuilder &Builder,
                                             std::string ArrayName) {
  assert(GlobalDescriptor && "invalid global descriptor given");
  Type *Ty = GlobalDescriptor->getType()->getPointerElementType();

  Value *endIdx[4] = {Builder.getInt64(0), Builder.getInt32(3),
                      Builder.getInt64(0), Builder.getInt32(2)};
  Value *endPtr = Builder.CreateInBoundsGEP(Ty, GlobalDescriptor, endIdx,
                                            ArrayName + "_end_ptr");
  Type *type = cast<GEPOperator>(endPtr)->getResultElementType();
  assert(isa<IntegerType>(type) && "expected type of end to be integral");

  Value *end = Builder.CreateLoad(type, endPtr, ArrayName + "_end");

  Value *beginIdx[4] = {Builder.getInt64(0), Builder.getInt32(3),
                        Builder.getInt64(0), Builder.getInt32(1)};
  Value *beginPtr = Builder.CreateInBoundsGEP(Ty, GlobalDescriptor, beginIdx,
                                              ArrayName + "_begin_ptr");
  Value *begin = Builder.CreateLoad(type, beginPtr, ArrayName + "_begin");

  Value *size =
      Builder.CreateNSWSub(end, begin, ArrayName + "_end_begin_delta");

  size = Builder.CreateNSWAdd(
      end, ConstantInt::get(type, 1, /* signed = */ true), ArrayName +
"_size");

  return size;
}

The first 'size' is created but never used; from the comment at the top, I
believe the code should be something like:

/// %0 = load i64, i64* getelementptr inbounds
///                       (%arrty, %arrty* @g_arr, i64 0, i32 3, i64 0, i32 2)
/// %1 = load i64, i64* getelementptr inbounds
///                      (%arrty, %arrty* @g_arr, i64 0, i32 3, i64 0, i32 1)
/// %2 = sub nsw i64 %0, %1
/// %size = add nsw i64 %2, 1

....

  Value *delta =
      Builder.CreateNSWSub(end, begin, ArrayName + "_end_begin_delta");

  Value *size = Builder.CreateNSWAdd(
      delta, ConstantInt::get(type, 1, /* signed = */ true), ArrayName +
"_size");

  return size;
}

-- 
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/20211014/092aa8fb/attachment.html>


More information about the llvm-bugs mailing list