LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1325 - miscompilation due to switch -> shift/and code
Summary: miscompilation due to switch -> shift/and code
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: 1.0
Hardware: All All
: P normal
Assignee: Anton Korobeynikov
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2007-04-13 21:24 PDT by Chris Lattner
Modified: 2010-02-22 12:45 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
Test .ll file (6.55 KB, text/plain)
2007-04-13 21:28 PDT, Chris Lattner
Details
.s file with shift/and enabled (3.80 KB, text/plain)
2007-04-13 21:28 PDT, Chris Lattner
Details
.s file with shift/and disabled (3.92 KB, text/plain)
2007-04-13 21:29 PDT, Chris Lattner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-04-13 21:24:29 PDT
Shift/And lowering is producing invalid code.  I'm not sure but I think that this is the issue:

LBB1_2:	;cond_next67
	lbz r2, 0(r29)
	li r3, 1
	cmplwi cr0, r2, 32
	slw r3, r3, r2
	bgt cr0, LBB1_4	;bb101.preheader

This allows a shift of 32.  On PPC, this will produce the same value as shifting by 31.  On X86, this 
produces the same value as shifting by 0.  This is the switch in question:

	switch i8 %tmp69, label %cond_next67.bb101_crit_edge [
		 i8 32, label %cond_next67.bb37_crit_edge
		 i8 9, label %cond_next67.bb37_crit_edge2
		 i8 10, label %cond_next67.bb37_crit_edge3
		 i8 13, label %cond_next67.bb37_crit_edge4
		 i8 12, label %cond_next67.bb37_crit_edge5
	]

That said, it is an impressive code size win :)

-Chris
Comment 1 Chris Lattner 2007-04-13 21:28:15 PDT
Created attachment 773 [details]
Test .ll file
Comment 2 Chris Lattner 2007-04-13 21:28:58 PDT
Created attachment 774 [details]
.s file with shift/and enabled
Comment 3 Chris Lattner 2007-04-13 21:29:34 PDT
Created attachment 775 [details]
.s file with shift/and disabled
Comment 4 Chris Lattner 2007-04-13 22:21:25 PDT
This also broke ppc bootstrap.
Comment 5 Anton Korobeynikov 2007-04-14 06:50:35 PDT
Mine. However, I thought this case was fixed before my commit :) Ok. Will
investigate.
Comment 6 Anton Korobeynikov 2007-04-14 08:30:15 PDT
Fixed with:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070409/047507.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070409/047506.html

Sorry for the breakage. I wasn't be able to test things on PowerPC and I cannot
understand PowerPC assembler yet :) Chris, could you please verify?

I also fixed some "latent" bug, which can be only triggered on 64-bit platforms.
Jeff, could you please check, whether this fixes some bugs for you or not.
Comment 7 Jeff Cohen 2007-04-14 11:46:41 PDT
It seems to work on freebsd/amd64.
Comment 8 Chris Lattner 2007-04-14 13:10:56 PDT
Verified that 253.perlbmk passes on ppc now.  ppc bootstrap still broken, I'll file a new bug if it's shift/
and.