[LLVMbugs] [Bug 21222] New: InstCombine: wrong folding of a constant comparison involving ashr and negative numbers.
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Oct 9 03:13:45 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=21222
Bug ID: 21222
Summary: InstCombine: wrong folding of a constant comparison
involving ashr and negative numbers.
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: andrea.dibiagio at gmail.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Reproducible:
;;
define i1 @test(i32 %B) {
%shr = ashr i32 -93, %B
%cmp = icmp eq i32 %shr, -2
ret i1 %cmp
}
;;
Function @test should return true when %B is equal to 6.
That is because -93 >> 6 = -2.
Currently the Instruction Combiner wrongly folds the entire function to a
`return i1 false`.
The problem is in the folding logic located in InstCombineCompares.cpp; method
InstCombiner::FoldICmpCstShrCst wrongly computes the distance (in binary)
between two negative values.
With:
AP1 < 0
AP2 < 0
AP2 != 0
AP1 != 0
AP1 > AP2
Currently the distance between AP2 and AP1 is wrongly computed as:
(-AP2).logBase2() - (-AP1).logBase2()
the distance between AP1 and AP2 should be computed instead taking the ones'
complement of AP2 and AP1:
(~AP2).logBase2() - (~AP1).logBase2()
This is another regression introduced by revision 213678 which, unfortunately
wasn't correctly fixed by revision 217950.
I have a fix for this bug which I plan to send soon for review on the mailing
list.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141009/bda4d4e0/attachment.html>
More information about the llvm-bugs
mailing list