Andrew Clinton
2012-Aug-20 18:50 UTC
[LLVMdev] How to eliminate PHI nodes on pointer types?
Somewhere during optimization PHI nodes on pointer types (including alloca instructions) are being introduced, and they persist through the scalar replacement of aggregates pass and others. I can't seem to find a combination of passes or transformations to get rid of them. Has anyone had this problem before, and know a transformation to eliminate it? My optimization passes rely on everything being in pure SSA form. One more note, this particular optimization problem only seems to occur in llvm 2.8, not 3.0 - though I can't say for sure whether it never happens in 3.0. Here's an example from the compiled code: define private void @"vop_bindST at FFIFFI"(double* %news, double* %ss, i32* %isSConnected, double* %newt, double* %tt, i32* %isTConnected) nounwind alwaysinline { entry: %"reg2mem alloca point" = bitcast i32 0 to i32 %isSConnected1 = load i32* %isSConnected %0 = icmp eq i32 %isSConnected1, 0 br i1 %0, label %false, label %true true: ; preds = %entry br label %end false: ; preds = %entry br label %end end: ; preds = %false, %true %phi.in.reg2mem.0 = phi double* [ @s, %false ], [ %ss, %true ] %phi = load double* %phi.in.reg2mem.0 store double %phi, double* %news %isTConnected4 = load i32* %isTConnected %1 = icmp eq i32 %isTConnected4, 0 br i1 %1, label %false6, label %true5 true5: ; preds = %end br label %end7 false6: ; preds = %end br label %end7 end7: ; preds = %false6, %true5 %phi9.in.reg2mem.0 = phi double* [ @t, %false6 ], [ %tt, %true5 ] %phi9 = load double* %phi9.in.reg2mem.0 store double %phi9, double* %newt ret void }
Hi Andrew,> Somewhere during optimization PHI nodes on pointer types (including > alloca instructions) are being introduced, and they persist through the > scalar replacement of aggregates pass and others. I can't seem to find > a combination of passes or transformations to get rid of them. Has > anyone had this problem before, and know a transformation to eliminate > it? My optimization passes rely on everything being in pure SSA form.why is this a problem? Presumably you are happy with phi nodes of integer or float type, why are phi nodes of pointer type problematic? Ciao, Duncan. PS: I'm not sure what you mean by "pure SSA form". Phi nodes are needed for values of pointer type exactly because these values are in SSA form...> > One more note, this particular optimization problem only seems to occur > in llvm 2.8, not 3.0 - though I can't say for sure whether it never > happens in 3.0. > > Here's an example from the compiled code: > > > define private void @"vop_bindST at FFIFFI"(double* %news, double* %ss, > i32* %isSConnected, double* %newt, double* %tt, i32* %isTConnected) > nounwind alwaysinline { > entry: > %"reg2mem alloca point" = bitcast i32 0 to i32 > %isSConnected1 = load i32* %isSConnected > %0 = icmp eq i32 %isSConnected1, 0 > br i1 %0, label %false, label %true > > true: ; preds = %entry > br label %end > > false: ; preds = %entry > br label %end > > end: ; preds = %false, %true > %phi.in.reg2mem.0 = phi double* [ @s, %false ], [ %ss, %true ] > %phi = load double* %phi.in.reg2mem.0 > store double %phi, double* %news > %isTConnected4 = load i32* %isTConnected > %1 = icmp eq i32 %isTConnected4, 0 > br i1 %1, label %false6, label %true5 > > true5: ; preds = %end > br label %end7 > > false6: ; preds = %end > br label %end7 > > end7: ; preds = %false6, %true5 > %phi9.in.reg2mem.0 = phi double* [ @t, %false6 ], [ %tt, %true5 ] > %phi9 = load double* %phi9.in.reg2mem.0 > store double %phi9, double* %newt > ret void > } > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Andrew Clinton
2012-Aug-20 20:39 UTC
[LLVMdev] How to eliminate PHI nodes on pointer types?
On 08/20/2012 03:46 PM, Duncan Sands wrote:> Hi Andrew, > >> Somewhere during optimization PHI nodes on pointer types (including >> alloca instructions) are being introduced, and they persist through the >> scalar replacement of aggregates pass and others. I can't seem to find >> a combination of passes or transformations to get rid of them. Has >> anyone had this problem before, and know a transformation to eliminate >> it? My optimization passes rely on everything being in pure SSA form. > why is this a problem? Presumably you are happy with phi nodes of integer > or float type, why are phi nodes of pointer type problematic? > > Ciao, Duncan. > > PS: I'm not sure what you mean by "pure SSA form". Phi nodes are needed for > values of pointer type exactly because these values are in SSA form...By "pure" I mean that the IR has no alloca instructions, ie. it all has been promoted to registers. It's easy to see that this is possible in the program I posted (by changing the PHI to one on loaded values rather than pointers). The presence of allocas is problematic since the analysis and lowering passes in my optimizer don't handle them. Andrew