On Wed, Nov 14, 2012 at 03:32:53PM +0800, 陳韋任 (Wei-Ren Chen) wrote:> On Tue, Nov 13, 2012 at 11:23:02PM -0800, Shuxin Yang wrote: > > Hi, All: > > > > Is it legal to delete empty infinite loop like this : "while(1) {}"? > > It is interesting that both llvm and gcc keep the loop, however Open64 > > delete it. > > I think it's illegal to delete such infinite loop, perhapes you should > file a bug report to open64. That's my 2 cents.The reason I think it's illegal is because if you remove it, then the behavior is different. One with infinite empty loop will run infinitely, the other w/o infinite empty loop will exit immediately. That's my point. Regards, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Following loop (in asm) is often seen in embedded programs. It is used to delay for certain amount of time. If it were not written in asm, compiler would blindly delete the entire loop. How can compiler know such DCE betray program intention? for (i = 0; i < N; i++) { nop; nop; nop } I guess in the gray area, if programmer do not want compiler do something he doesn't expect, he/she perhaps have to resort to some esoteric ways. Compiler would otherwise have hard time in analyzing. On 11/13/2012 11:46 PM, 陳韋任 (Wei-Ren Chen) wrote:> On Wed, Nov 14, 2012 at 03:32:53PM +0800, 陳韋任 (Wei-Ren Chen) wrote: >> On Tue, Nov 13, 2012 at 11:23:02PM -0800, Shuxin Yang wrote: >>> Hi, All: >>> >>> Is it legal to delete empty infinite loop like this : "while(1) {}"? >>> It is interesting that both llvm and gcc keep the loop, however Open64 >>> delete it. >> I think it's illegal to delete such infinite loop, perhapes you should >> file a bug report to open64. That's my 2 cents. > The reason I think it's illegal is because if you remove it, then the > behavior is different. One with infinite empty loop will run infinitely, > the other w/o infinite empty loop will exit immediately. That's my > point. > > Regards, > chenwj >
On Wed, Nov 14, 2012 at 12:17:31AM -0800, Shuxin Yang wrote:> Following loop (in asm) is often seen in embedded programs. It is > used to delay for certain amount of time. > If it were not written in asm, compiler would blindly delete the > entire loop. How can compiler know such DCE > betray program intention? > for (i = 0; i < N; i++) { nop; nop; nop }The canonical example of doing this in a safe way is to touch a volatile variable. Joerg