Index: lib/Analysis/BasicAliasAnalysis.cpp =================================================================== --- lib/Analysis/BasicAliasAnalysis.cpp +++ lib/Analysis/BasicAliasAnalysis.cpp @@ -819,7 +819,7 @@ // If the last (struct) indices are constants and are equal, the other indices // might be also be dynamically equal, so the GEPs can alias. - if (C1 && C2 && C1 == C2) + if (C1 && C2 && C1->getSExtValue() == C2->getSExtValue()) return MayAlias; // Find the last-indexed type of the GEP, i.e., the type you'd get if Index: test/Analysis/BasicAA/gep-alias.ll =================================================================== --- test/Analysis/BasicAA/gep-alias.ll +++ test/Analysis/BasicAA/gep-alias.ll @@ -275,4 +275,21 @@ ret void } +; PR27418 - Treat GEP indices with the same value but different types the same +; CHECK-LABEL: @f( +define i1 @f() { + %arr = alloca [2 x i16] + %tmp1 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i32 1 + store i16 0, i16* %tmp1 + %tmp2 = getelementptr [2 x i16], [2 x i16]* %arr, i16 0, i16 1 + %tmp3 = load i16, i16* %tmp2 + %tmp4 = icmp ne i16 %tmp3, 0 + br i1 %tmp4, label %bb1, label %bb2 +; CHECK-NOT: br i1 undef, label %bb1, label %bb2 +bb1: + ret i1 false +bb2: + ret i1 true +} + declare i32 @printf(i8*, ...)