Dear All, Is there a pass (or set of passes) that will replace a phi whose input operands all compute the same value with an instruction that computes that value? In other words, something that will convert: define internal i32 @function(i32 %x) { ... bb1: %y = add %x, 10 ... bb2: %z = add %x, 10 ... bb3: %phi = [bb1, %y], [bb2, %z] into define internal i32 @function(i32 %x) { ... bb1: ... bb2: ... bb3: %phi = add %x, 10 -- John T.
Hi John, On 30/07/13 16:12, John Criswell wrote:> Dear All, > > Is there a pass (or set of passes) that will replace a phi whose input operands > all compute the same value with an instruction that computes that value? In > other words, something that will convert: > > define internal i32 @function(i32 %x) { > ... > bb1: > %y = add %x, 10 > ... > bb2: > %z = add %x, 10 > ... > bb3: > %phi = [bb1, %y], [bb2, %z] > > into > > define internal i32 @function(i32 %x) { > ... > bb1: > ... > bb2: > ... > bb3: > %phi = add %x, 10yes, GVN should replace %y and %z with the same register, giving something like %same = add %x, 10 ... bb1: ... bb2: ... bb3: %phi = [bb1, %same], [bb2, %same] at which point the instcombine pass should zap the phi, though maybe GVN will get it already. Ciao, Duncan.
On 7/30/13 9:46 AM, Duncan Sands wrote:> Hi John, > > On 30/07/13 16:12, John Criswell wrote: >> Dear All, >> >> Is there a pass (or set of passes) that will replace a phi whose >> input operands >> all compute the same value with an instruction that computes that >> value? In >> other words, something that will convert: >> >> define internal i32 @function(i32 %x) { >> ... >> bb1: >> %y = add %x, 10 >> ... >> bb2: >> %z = add %x, 10 >> ... >> bb3: >> %phi = [bb1, %y], [bb2, %z] >> >> into >> >> define internal i32 @function(i32 %x) { >> ... >> bb1: >> ... >> bb2: >> ... >> bb3: >> %phi = add %x, 10 > > yes, GVN should replace %y and %z with the same register, giving > something like > > %same = add %x, 10 > ... > bb1: > ... > bb2: > ... > bb3: > %phi = [bb1, %same], [bb2, %same] > > at which point the instcombine pass should zap the phi, though maybe > GVN will > get it already.Odd. I'm running GVN and then InstCombine, and it doesn't fix the problem. Is this new behavior added since LLVM 3.2, or is this something that GVN has been doing for awhile? -- John T.> > Ciao, Duncan. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu llvm.cs.uiuc.edu > lists.cs.uiuc.edu/mailman/listinfo/llvmdev