[InstCombine] Optimize select(freeze(icmp eq/ne x, y), x, y)
authorJuneyoung Lee <aqjune@gmail.com>
Fri, 7 Aug 2020 12:12:52 +0000 (21:12 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Sat, 8 Aug 2020 06:22:29 +0000 (15:22 +0900)
commitb6d9add71b1a7bc77ce504ed09a43288ca67c0cd
treedc6824bea08d2ec56131b535eb275a1fd74500cd
parent5d59385ba67ec20dc4a3e13b9a7088ace970df4d
[InstCombine] Optimize select(freeze(icmp eq/ne x, y), x, y)

This patch adds an optimization that folds select(freeze(icmp eq/ne x, y), x, y)
to x or y.
This was needed to resolve slowdown after D84940 is applied.

I tried to bake this logic into foldSelectInstWithICmp, but it wasn't clear.
This patch conservatively writes the pattern in a separate function,
foldSelectWithFrozenICmp.

The output does not need freeze; https://alive2.llvm.org/ce/z/X49hNE (from @nikic)

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D85533
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select.ll