[PATCH] D29088: Do not create ctlz/cttz(X, false) when the target do not support zero defined ctlz/cttz.

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 13:45:02 PST 2017


spatel added a comment.

This patch goes against my understanding that InstCombine is only for target-independent transforms.

Like Andrea and Hal have requested, I'd like to see an example for how we get to the problem state.
I tried to put together an IR example from what you described here:
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109398.html

  int goo(int n) {
    int a = (n == 0x0) ? 32 : __builtin_clz(n) ;
    int b = ((a * 36) + 35) >> 8;
    return b;
  }

$ ./clang -O2 ctlz.c  -S  -o - -emit-llvm

  source_filename = "ctlz.c"
  target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-apple-macosx10.12.0"
  
  define i32 @goo(i32 %n) local_unnamed_addr #0 {
  entry:
    %cmp = icmp eq i32 %n, 0
    br i1 %cmp, label %cond.end, label %cond.false
  
  cond.false:  
    %0 = tail call i32 @llvm.ctlz.i32(i32 %n, i1 true)
    %phitmp = mul nuw nsw i32 %0, 36
    %phitmp4 = add nuw nsw i32 %phitmp, 35
    %phitmp56 = lshr i32 %phitmp4, 8
    br label %cond.end
  
  cond.end:  
    %cond = phi i32 [ %phitmp56, %cond.false ], [ 4, %entry ]  <--- constant folded as expected?
    ret i32 %cond
  }


https://reviews.llvm.org/D29088





More information about the llvm-commits mailing list