[LLVMbugs] [Bug 13549] New: Reassociate: should we convert c*c+c+c+c*c*c to c*(c*c+c+2)? We currently have c*(c*c+c)+c*2.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Aug 7 17:01:01 PDT 2012


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

             Bug #: 13549
           Summary: Reassociate: should we convert c*c+c+c+c*c*c to
                    c*(c*c+c+2)? We currently have c*(c*c+c)+c*2.
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: mren at apple.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


#include <cstdio>
size_t ComputeMemSize(int hps) {
  size_t ps = hps;
  size_t memSize = 0;

  memSize += ps*ps;
  memSize += hps;
  memSize += hps;
  memSize += ps*ps*hps;
  return memSize;
}

clang -O3 test.cpp -emit-llvm -S -o -
define i64 @_Z14ComputeMemSizei(i32 %hps) nounwind uwtable readnone ssp {
entry:
  %conv = sext i32 %hps to i64
  %mul = mul i64 %conv, %conv
  %factor = shl nsw i64 %conv, 1
  %mul79 = add i64 %mul, %conv
  %add4 = mul i64 %conv, %mul79
  %add8 = add i64 %add4, %factor
  ret i64 %add8
}
// c*(c*c+c) + c*2

Should we perform further reassociate to generate?
define i64 @_Z14ComputeMemSizei(i32 %hps) nounwind uwtable readnone ssp {
entry:
  %conv = sext i32 %hps to i64
  %mul = mul i64 %conv, %conv
  %tmp = add i64 %mul, 2
  %tmp12 = add i64 %tmp, %conv
  %add8 = mul i64 %conv, %tmp12
  ret i64 %add8
}
// c*(c*c+2+c)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list