[PATCH] D14590: [SimplifyLibCalls] Constant folding for fls, flsl, flsll

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 19:48:43 PST 2016

davide added a comment.

In https://reviews.llvm.org/D14590#623196, @davide wrote:

> SimplifyLibCalls needs to know how to translate the pair `(DataLayout, C99 type)` -> `LLVM IR Type` in order to make this transformation. Until then, there's no reliable way to know how big a `long` is and that could cause a wrong constant folding of `fls()`. I haven't audited all the transformations here, but I wouldn't be surprised if other functions are incorrectly transformed assuming sizes of primitive types.


In https://reviews.llvm.org/D14590#623203, @efriedma wrote:

> I'm not sure I follow the issue with `long`.  If we see `call i32 @flsl(i32 42)` in the IR, "long" must be 32 bits; if we see `call i32 @flsl(i64 42)` in the IR, "long" must be 64 bits.

You're absolutely right, there's no such problem as we actually have the type. I was under the impression we needed the correspondence with the C type but I was clearly wrong. Well, thanks for catching.
I updated the patch, which also revealed a bug in `TargetLibraryInfo` while checking the function prototype.
Can you please take a look?


More information about the llvm-commits mailing list