[llvm-commits] Fix for bug 14986
Sebastien DELDON-GNB
sebastien.deldon at st.com
Wed Jan 23 01:39:42 PST 2013
Hi all,
This is my first post on this mailing list, so hope I'm doing the right thing. If not sorry about it.
Here is my proposed fix for bug 14986, filed by myself. One problem with this fix is that
getelementptr.ll test reports an error. I think error reported by getelementptr.ll test might not be correct,
here is error I've got:
/work1/tools/llvm/trunk/sources/test/Transforms/InstCombine/getelementptr.ll:438:10: error: expected string not found in input
; CHECK: ret i8* getelementptr ([11 x i8]* @array, i64 1676976733973595601, i64 4)
^
<stdin>:253:19: note: scanning from here
define i8* @test36() nounwind {
^
<stdin>:254:2: note: possible intended match here
ret i8* getelementptr ([11 x i8]* @array, i64 -1, i64 10)
^
--
Here is my proposed patch.
Index: ConstantFolding.cpp
===================================================================
--- ConstantFolding.cpp (revision 173137)
+++ ConstantFolding.cpp (working copy)
@@ -736,8 +736,13 @@
else {
// The element size is non-zero divide the offset by the element
// size (rounding down), to compute the index at this level.
- APInt NewIdx = Offset.udiv(ElemSize);
+ APInt NewIdx = Offset.sdiv(ElemSize);
Offset -= NewIdx * ElemSize;
+
+ if (Offset.isNegative()) {
+ NewIdx-- ;
+ Offset += ElemSize ;
+ }
NewIdxs.push_back(ConstantInt::get(IntPtrTy, NewIdx));
}
Ty = ATy->getElementType();
More information about the llvm-commits
mailing list