llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Failure to reach fixpoint in 1st iteration when constant folding libcall

Open lukel97 opened this issue 3 months ago • 2 comments

https://llvm.godbolt.org/z/456M4eq6f

We constant fold the call to floor, but it's not trivially dead so it hangs around after being RAUWd. Maybe we should mark the TargetLibraryInfo::hasOptimizedCodeGen functions as trivially dead?

lukel97 avatar Aug 21 '26 07:08 lukel97

I believe the problem is that prepareWorklist() fails to add the instruction to the worklist if it constant folds but is not trivially dead.

(The specific example will optimize in one iteration in practice, because it will have inferred attributes that make it trivially dead.)

nikic avatar Aug 21 '26 08:08 nikic

Hello. I have tried a fix based on nikic's suggestion and can provide a PR.

tadeuszjt avatar Aug 24 '26 15:08 tadeuszjt