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

            Bug ID: 34603
           Summary: failed to hoist load through select-of-pointers?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: spatel+l...@rotateright.com
                CC: llvm-bugs@lists.llvm.org

Forking this off from bug 28343:

double max_of_loads(double *x, double *y, int i) {
  return x[i] > y[i] ? x[i] : y[i];
}

$ ./clang maxload.c -S -O2 -o - -emit-llvm
define double @max_of_loads(double* nocapture readonly %x, double* nocapture
readonly %y, i32 %i) {
entry:
  %idxprom = sext i32 %i to i64
  %arrayidx1 = getelementptr inbounds double, double* %x, i64 %idxprom
  %0 = load double, double* %arrayidx1, align 8, !tbaa !3
  %arrayidx2 = getelementptr inbounds double, double* %y, i64 %idxprom
  %1 = load double, double* %arrayidx2, align 8, !tbaa !3
  %cmp = fcmp ogt double %0, %1
  %.sink = select i1 %cmp, double* %x, double* %y
  %arrayidx6 = getelementptr inbounds double, double* %.sink, i64 %idxprom
  %2 = load double, double* %arrayidx6, align 8, !tbaa !3
  ret double %2
}

------------------------------------------------------------------------

I don't think there's any alias-based restrictions impeding this transform?

define double @max_of_loads(double* nocapture readonly %x, double* nocapture
readonly %y, i32 %i) {
entry:
  %idxprom = sext i32 %i to i64
  %arrayidx = getelementptr inbounds double, double* %x, i64 %idxprom
  %arrayidx2 = getelementptr inbounds double, double* %y, i64 %idxprom
  %0 = load double, double* %arrayidx, align 8, !tbaa !3
  %1 = load double, double* %arrayidx2, align 8, !tbaa !3
  %cmp = fcmp ogt double %0, %1
  %sel = select i1 %cmp, double %0, double %1
  ret double %sel
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to