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 1014 - instcombine + dagcombine miscompilation
Summary: instcombine + dagcombine miscompilation
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Chris Lattner
URL:
Keywords: miscompilation
Depends on:
Blocks:
 
Reported: 2006-11-27 10:31 PST by Anton Korobeynikov
Modified: 2018-11-07 00:17 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments
Test source (1.01 KB, text/plain)
2006-11-27 10:32 PST, Anton Korobeynikov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Korobeynikov 2006-11-27 10:31:38 PST
Consider the attached .ll file.

It will ask a number as input. Input "32".
Correct answer is "41". It can be obtained via cbackend. Both llc and lli
generate code, which produces "186".
Comment 1 Anton Korobeynikov 2006-11-27 10:32:24 PST
Created attachment 474 [details]
Test source
Comment 2 Anton Korobeynikov 2006-11-27 10:46:03 PST
This is definitely bug in InstCombine.

opt -instcombine produces bad output
Comment 3 Reid Spencer 2006-11-27 10:48:10 PST
Hmm, no cast instructions.

What does instcombine produce? Can you attach it please?

Reid.
Comment 4 Anton Korobeynikov 2006-11-27 10:49:22 PST
Before:

        %ovm = and int %tmp1, 32                ; <int> [#uses=1]
        %ov3 = add int %ovm, 145                ; <int> [#uses=2]
        %ov110 = xor int %ov3, 153
        %hvar174 = add int %ov110, 1

After:

        %ovm = and int %tmp1, 32                ; <int> [#uses=1]
        %ov1102 = or int %ovm, 153              ; <int> [#uses=1]
        %hvar174 = add int %ov1102, 1           ; <int> [#uses=1]
Comment 5 Chris Lattner 2006-11-27 13:56:11 PST
Fixed.  Testcase here: InstCombine/2006-11-27-XorBug.ll  Patch here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061127/040292.html

-Chris
Comment 6 Anton Korobeynikov 2006-11-27 14:47:19 PST
Attached testcase is still broken.
Comment 7 Anton Korobeynikov 2006-11-27 14:48:54 PST
In fact, I haven't found any output difference before and after patch.
Comment 8 Chris Lattner 2006-11-27 15:43:58 PST
I get:
$ llvm-as < t.ll | opt -instcombine | llvm-dis
...
int %main() {
entry:
        %v0 = alloca int, align 4               ; <int*> [#uses=2]
        %tmp = call int (sbyte*, ...)* %scanf( sbyte* getelementptr ([3 x sbyte]* %str, int 0, uint 0), int* %v0 
)              ; <int> [#uses=0]
        %tmp1 = load int* %v0           ; <int> [#uses=1]
        %ovm = and int %tmp1, 32                ; <int> [#uses=1]
        %hvar1742 = or int %ovm, 9              ; <int> [#uses=1]
        %tmp3 = call int (sbyte*, ...)* %printf( sbyte* getelementptr ([4 x sbyte]* %str, int 0, uint 0), int %
hvar1742 )               ; <int> [#uses=0]
        br label %return

return:         ; preds = %entry
        ret int 0
}
..

You don't get this?

Comment 9 Chris Lattner 2006-11-27 15:50:51 PST
This same bug also exists in the dag combiner.  Fixed like this:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061127/040294.html

-Chris