[all-commits] [llvm/llvm-project] 9adedd: [InstCombine] Relax preconditions for ashr+and+icm...
Nikita Popov via All-commits
all-commits at lists.llvm.org
Tue Feb 18 08:51:10 PST 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 9adedd146d53101059a3884c2453f15646bc863a
https://github.com/llvm/llvm-project/commit/9adedd146d53101059a3884c2453f15646bc863a
Author: Nikita Popov <nikita.ppv at gmail.com>
Date: 2020-02-18 (Tue, 18 Feb 2020)
Changed paths:
M llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
M llvm/test/Transforms/InstCombine/icmp.ll
Log Message:
-----------
[InstCombine] Relax preconditions for ashr+and+icmp fold (PR44754)
Fix for https://bugs.llvm.org/show_bug.cgi?id=44754. We already have
a fold that converts icmp (and (ashr X, C3), C2), C1 into
icmp (and C2'), C1', but it imposed overly strict requirements on the
transform.
Relax this by checking that both C2 and C1 don't shift out bits
(in a signed sense) when forming the new constants.
Alive proofs (https://rise4fun.com/Alive/PTz0):
Name: ashr_legal
Pre: ((C2 << C3) >> C3) == C2 && ((C1 << C3) >> C3) == C1
%a = ashr i16 %x, C3
%b = and i16 %a, C2
%c = icmp i16 %b, C1
=>
%d = and i16 %x, C2 << C3
%c = icmp i16 %d, C1 << C3
Name: ashr_shiftout_eq
Pre: ((C2 << C3) >> C3) == C2 && ((C1 << C3) >> C3) != C1
%a = ashr i16 %x, C3
%b = and i16 %a, C2
%c = icmp eq i16 %b, C1
=>
%c = false
Note that >> corresponds to ashr here. The case of an equality
comparison has some special handling in this transform, because
it will form to a true/false result if the condition on the comparison
constant it violated.
Differential Revision: https://reviews.llvm.org/D74294
More information about the All-commits
mailing list