[llvm] [RISCV] Enable early if-conversion (PR #92959)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 03:44:28 PDT 2024


https://github.com/wangpc-pp commented:

I just have evaluated this patch, and I think there is a room for more optimizations:
```c
int loop(int m, int n, int *randArray) {
  int t = 0;
  for (int j = 0; j < n; j++) {
    for (int i = 0; i < 4 + m; i++) {
      if (randArray[i]) {
        t += 3 + 3 * t;
      } else {
        t -= 1 - 5 * t;
      }
    }
  }
  return t;
}
```
For this case, I compared the results of two configurations:
1.  `clang -O2 -march=rv64gc_zba_zbb_zbc_zbs_zicond -mllvm -two-entry-phi-node-folding-threshold=16`. I increased the threshold so that we can do if conversion in LLVM IR level via `SimplifyCFG`.
2.  `clang -O2 -march=rv64gc_zba_zbb_zbc_zbs_zicond -mllvm -riscv-disable-early-ifcvt=false -mllvm -riscv-force-early-ifcvt=true -mllvm -stress-early-ifcvt=true`.
The diff is:
![图片](https://github.com/llvm/llvm-project/assets/137158460/177da652-3b3d-4c02-86b5-0575960aa75c)

We can remove the `xor`+`seqz` here.

https://github.com/llvm/llvm-project/pull/92959


More information about the llvm-commits mailing list