[PATCH] [AArch64] Generate tbz/tbnz when comparing against zero.

Xu Jiangwei xjwwm_cat at 163.com
Wed Jul 9 22:59:20 PDT 2014


I have tried your patch and test.Here, I doubt whether it has something to do with add/sub or adds/subs, and I have also tried some test case written by myself. 
  void foo();
  void gt(int tmp) {
    if (tmp >= 0)
      foo();
  }

and the asm is below:
    ge:                                     // @ge 
  // BB#0:                                // %entry 
          cmp      w0, #0                 // =0 
          b.lt    .LBB1_2                           
  // BB#1:                                // %if.then 
          b       foo 
  .LBB1_2:                                // %if.end 
          ret 
  .Ltmp3:
        .size   ge, .Ltmp3-ge

I think the cmp and b.lt above can combine to tbz/tbnz. I think your patch should cover this case. When I chang the c code to (tmp>0), it generates 
  gt:                                     // @gt
  // BB#0:                                // %entry
         cmp      w0, #1                 // =1
         b.lt    .LBB0_2
  // BB#1:                                // %if.then
         b       foo
  .LBB0_2:                                // %if.end
         ret
I think this case may not be easy to generate TBZ/TBNZ, what is your opinion?

Thanks
-David

http://reviews.llvm.org/D4440






More information about the llvm-commits mailing list