[PATCH] D30689: [ConstantFolding] Small fix to prevent constant folding having to repeatedly scan operands.

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 06:24:43 PST 2017


dmgreen added a comment.

I've put together a little reproducer. The original case was from the preprocessed CSiBE lwip-0.5.3.preproc/src/core/memp.i source file, this shows the same thing going on:

  struct ST {
      struct ST* next;
  };
  static char global[LOOP*sizeof(struct ST)+1];
  #define ALIGN(m, y) (m + ((m%y==0) ? 0 : m%y))
  void func(void)
  {
      struct ST* s = (struct ST*)&global;
      for(int j = 0; j < LOOP; j++) {
          s->next = (struct ST*)ALIGN((unsigned)((char*)s+sizeof(struct ST)), 2);
          s = s->next;
      }
      s->next = 0;
  }

Compiling with something like "clang -c simple.c -O3 -DLOOP=X" I get these compile times for various values of LOOP:

10 0.2
12 0.3
14 0.6
16 1.2
18 8.6
20 33.9
22 215.0


https://reviews.llvm.org/D30689





More information about the llvm-commits mailing list