Zhou Sheng
2007-Nov-23 03:07 UTC
[LLVMdev] Will any pass change simple return branch into select/return pair?
Hi, Can any llvm pass change simple return branch into select/return pair? For example: define i10 @mod_N(i10 zeroext %a) zeroext { entry: %tmp2 = icmp ugt i10 %a, -400 ; <i1> [#uses=1] br i1 %tmp2, label %cond_true, label %return cond_true: ; preds = %entry %tmp5 = add i10 %a, 400 ; <i10> [#uses=1] ret i10 %tmp5 return: ; preds = %entry ret i10 %a } Changed into: define i10 @mod_N(i10 zeroext %a) zeroext { entry: %tmp2 = icmp ugt i10 %a, -400 ; <i1> [#uses=1] %tmp5 = add i10 %a, 400 ; <i10> [#uses=1] %retval = select i1 %tmp2, i10 %tmp5, i10 %a ; <i10> [#uses=1] ret i10 %retval } Thanks in advance. Sheng. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20071123/a7343111/attachment.html>
Chris Lattner
2007-Nov-23 06:20 UTC
[LLVMdev] Will any pass change simple return branch into select/return pair?
On Fri, 23 Nov 2007, Zhou Sheng wrote:> Can any llvm pass change simple return branch into select/return pair? > For example:Yes, simplifycfg does this. However, it doesn't do it for your example, because the add is in one of the blocks. Simplifycfg won't change the code to unconditionally execute it. This sort of thing is traditionally handled in the code generator. For example, the ARM backend uses a predication pass to execute instrutions conditionally. -Chris> define i10 @mod_N(i10 zeroext %a) zeroext { > entry: > %tmp2 = icmp ugt i10 %a, -400 ; <i1> [#uses=1] > br i1 %tmp2, label %cond_true, label %return > > cond_true: ; preds = %entry > %tmp5 = add i10 %a, 400 ; <i10> [#uses=1] > ret i10 %tmp5 > > return: ; preds = %entry > ret i10 %a > } > > Changed into: > > define i10 @mod_N(i10 zeroext %a) zeroext { > entry: > %tmp2 = icmp ugt i10 %a, -400 ; <i1> [#uses=1] > %tmp5 = add i10 %a, 400 ; <i10> [#uses=1] > %retval = select i1 %tmp2, i10 %tmp5, i10 %a ; <i10> [#uses=1] > ret i10 %retval > } > > Thanks in advance. > > Sheng. >-Chris -- http://nondot.org/sabre/ http://llvm.org/
Seemingly Similar Threads
- [LLVMdev] Labels
- [LLVMdev] A question about GetElementPtr common subexpression elimination/loop invariant code motion
- [LLVMdev] How to place call(s) to functions found in other llvm modules ???
- InstructionSimplify: adding a hook for shufflevector instructions
- Accessing data