[PATCH] D71312: [InstCombine] Fold X / abs(X) to X < 0 ? -1 : 1
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 16:55:28 PST 2019
xbolva00 added a comment.
In D71312#1778626 <https://reviews.llvm.org/D71312#1778626>, @craig.topper wrote:
> Isn't it sufficient to just check that the true/false values of the select are x and -x. The condition itself doesn't matter. x / (select c, x, -x) -> select c ? 1 : -1
Name: div abs
%cmp = icmp slt i32 %x, 0
%sub = sub nsw i32 0, %x
%cond = select i1 %cmp, i32 %sub, i32 %x
%div = sdiv i32 %x, %cond
=>
%div = select i1 %cmp, i32 -1, i32 1
Right.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71312/new/
https://reviews.llvm.org/D71312
More information about the llvm-commits
mailing list