diff options
author | David Majnemer <david.majnemer@gmail.com> | 2013-06-29 10:28:04 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2013-06-29 10:28:04 +0000 |
commit | 5953d3712abd7b3fdb0f8442cd594350a1209204 (patch) | |
tree | 8ef70c85ea4a08ee05bacea688c6a62d4146ba2b | |
parent | 92a8a7d45abc8207ee9a9c5282da7dc151aff3c7 (diff) | |
download | bcm5719-llvm-5953d3712abd7b3fdb0f8442cd594350a1209204.tar.gz bcm5719-llvm-5953d3712abd7b3fdb0f8442cd594350a1209204.zip |
InstCombine: FoldGEPICmp shouldn't change sign of base pointer comparison
Changing the sign when comparing the base pointer would introduce all
sorts of unexpected things like:
%gep.i = getelementptr inbounds [1 x i8]* %a, i32 0, i32 0
%gep2.i = getelementptr inbounds [1 x i8]* %b, i32 0, i32 0
%cmp.i = icmp ult i8* %gep.i, %gep2.i
%cmp.i1 = icmp ult [1 x i8]* %a, %b
%cmp = icmp ne i1 %cmp.i, %cmp.i1
ret i1 %cmp
into:
%cmp.i = icmp slt [1 x i8]* %a, %b
%cmp.i1 = icmp ult [1 x i8]* %a, %b
%cmp = xor i1 %cmp.i, %cmp.i1
ret i1 %cmp
By preserving the original sign, we now get:
ret i1 false
This fixes PR16483.
llvm-svn: 185259
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/getelementptr.ll | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index ff207fb1b69..0f1576050ff 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -647,8 +647,7 @@ Instruction *InstCombiner::FoldGEPICmp(GEPOperator *GEPLHS, Value *RHS, // If all indices are the same, just compare the base pointers. if (IndicesTheSame) - return new ICmpInst(ICmpInst::getSignedPredicate(Cond), - GEPLHS->getOperand(0), GEPRHS->getOperand(0)); + return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0)); // If we're comparing GEPs with two base pointers that only differ in type // and both GEPs have only constant indices or just one use, then fold diff --git a/llvm/test/Transforms/InstCombine/getelementptr.ll b/llvm/test/Transforms/InstCombine/getelementptr.ll index bb07736ef80..844678a6745 100644 --- a/llvm/test/Transforms/InstCombine/getelementptr.ll +++ b/llvm/test/Transforms/InstCombine/getelementptr.ll @@ -509,4 +509,14 @@ define void @test39(%struct.ham* %arg, i8 %arg1) nounwind { ; CHECK: getelementptr inbounds i8* %tmp3, i64 -8 } +define i1 @pr16483([1 x i8]* %a, [1 x i8]* %b) { + %c = getelementptr [1 x i8]* %a, i32 0, i32 0 + %d = getelementptr [1 x i8]* %b, i32 0, i32 0 + %cmp = icmp ult i8* %c, %d + ret i1 %cmp + +; CHECK: @pr16483 +; CHECK-NEXT: icmp ult [1 x i8]* %a, %b +} + ; CHECK: attributes [[NUW]] = { nounwind } |