OSDN Git Service

InstCombine: FoldGEPICmp shouldn't change sign of base pointer comparison
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 29 Jun 2013 10:28:04 +0000 (10:28 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 29 Jun 2013 10:28:04 +0000 (10:28 +0000)
commitc22a4eeec6967454c73d1430398298259e468b92
tree14b9792948e7e52a4812d49e5016835663f4f861
parentdf703257c1dafed4cdb803996a5c277d95780799
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185259 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/getelementptr.ll