[llvm] [ConstantFolding] Add ilogb in isMathLibCallNoop (PR #122582)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 13 21:11:00 PST 2025


================

----------------
c8ef wrote:

> It seems this simplification is happening in EarlyCSE and not instcombine. Ran this after applying OP's patch.
> 
> `opt -O3 llvm/test/Transforms/InstCombine/ilogb.ll -S -print-after-all -print-before-all -filter-print-funcs=ilogb_const1`
> 
> ```
> ; *** IR Dump Before EarlyCSEPass on ilogb_const1 ***
> define i32 @ilogb_const1() {
>   %r = call i32 @ilogb(double -7.000000e+00)
>   ret i32 %r
> }
> ; *** IR Dump After EarlyCSEPass on ilogb_const1 ***
> define i32 @ilogb_const1() {
>   ret i32 2
> }
> ```

The constant folding part is invoked in the EarlyCSEPass, but it does not delete the original call. As far as I know, to delete the original function call, we need to prove it has no side effects. This part happens in the SimplifyCFG pass, which utilizes the InstSimplify functionality and eventually calls llvm::isMathLibCallNoop.

ref: https://godbolt.org/z/azosfrK49

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


More information about the llvm-commits mailing list