-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Description
| Bugzilla Link | 34228 |
| Version | trunk |
| OS | Linux |
| CC | @topperc,@RKSimon,@rotateright |
Extended Description
The following transformation doesn't happen:
%shared = add i64 %x, %y
%r1 = select i1 %c1, i64 %shared, i64 %x
%r2 = select i1 %c2, i64 %shared, i64 %y
%tmp = select i1 %c2, i64 %x, i64 0
%r2_eq1 = add i64 %tmp, %y
%r2_eq2 = select i1 %zzz, i64 %r2, i64 %r2_eq1
%r = add i64 %r1, %r2_eq2
=>
%shared = add i64 %x, %y
%r1 = select i1 %c1, i64 %shared, i64 %x
%r2 = select i1 %c2, i64 %shared, i64 %y
%r = add i64 %r1, %r2
http://rise4fun.com/Alive/IOS5
InstCombine can do the following canonicalization (see comment in getSelectFoldableOperands()):
%shared = add i64 %x, %y
%r2 = select i1 %c2, i64 %shared, i64 %y
=>
%tmp = select i1 %c2, i64 %x, i64 0
%r2 = add i64 %tmp, %y
But in this case the canonicalization doesn't happen, because %shared has two uses. Note that %r2_eq1 actually is the canonical form of %r2. Further canonicalization of either %r2 or %r2_eq1 won't happen. This is why the optimizer doesn't see that %r2_eq2 selects between two equivalent operands (and is therefore equal to %r2).