[llvm-commits] [llvm] r151452 - in /llvm/trunk: lib/Analysis/InstructionSimplify.cpp test/Transforms/InstSimplify/compare.ll
Nick Lewycky
nicholas at mxc.ca
Sat Feb 25 12:19:07 PST 2012
Author: nicholas
Date: Sat Feb 25 14:19:07 2012
New Revision: 151452
URL: http://llvm.org/viewvc/llvm-project?rev=151452&view=rev
Log:
An argument and a local identified object (eg. a noalias call) could turn out
equal if both are null. In the test, scope type %t and global @y by adding a
'gep' prefix to them.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/test/Transforms/InstSimplify/compare.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=151452&r1=151451&r2=151452&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Sat Feb 25 14:19:07 2012
@@ -1626,21 +1626,22 @@
LHSPtr = stripPointerAdjustments(LHSPtr);
if (llvm::isIdentifiedObject(LHSPtr)) {
RHSPtr = stripPointerAdjustments(RHSPtr);
- // If both sides are different identified objects, they aren't equal unless
- // they're null.
- if (LHSPtr != RHSPtr && llvm::isIdentifiedObject(RHSPtr) &&
- (llvm::isKnownNonNull(LHSPtr) || llvm::isKnownNonNull(RHSPtr)))
- return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
+ if (llvm::isKnownNonNull(LHSPtr) || llvm::isKnownNonNull(RHSPtr)) {
+ // If both sides are different identified objects, they aren't equal
+ // unless they're null.
+ if (LHSPtr != RHSPtr && llvm::isIdentifiedObject(RHSPtr))
+ return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
+
+ // A local identified object (alloca or noalias call) can't equal any
+ // incoming argument, unless they're both null.
+ if ((isa<Instruction>(LHSPtr) && isa<Argument>(RHSPtr)) ||
+ (isa<Instruction>(RHSPtr) && isa<Argument>(LHSPtr)))
+ return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
+ }
- // Assume that the null is on the right.
+ // Assume that the constant null is on the right.
if (llvm::isKnownNonNull(LHSPtr) && isa<ConstantPointerNull>(RHSPtr))
return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
-
- // A local instruction (alloca or noalias call) can't equal any incoming
- // argument.
- if ((isa<Instruction>(LHSPtr) && isa<Argument>(RHSPtr)) ||
- (isa<Instruction>(RHSPtr) && isa<Argument>(LHSPtr)))
- return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
}
// If we are comparing with zero then try hard since this is a common case.
Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=151452&r1=151451&r2=151452&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Sat Feb 25 14:19:07 2012
@@ -41,14 +41,15 @@
}
; PR11238
-%t = type { i32, i32 }
- at y = global %t zeroinitializer, align 8
+%gept = type { i32, i32 }
+ at gepy = global %gept zeroinitializer, align 8
+ at gepz = extern_weak global %gept
define i1 @gep3() {
; CHECK: @gep3
- %x = alloca %t, align 8
- %a = getelementptr %t* %x, i64 0, i32 0
- %b = getelementptr %t* %x, i64 0, i32 1
+ %x = alloca %gept, align 8
+ %a = getelementptr %gept* %x, i64 0, i32 0
+ %b = getelementptr %gept* %x, i64 0, i32 1
%equal = icmp eq i32* %a, %b
ret i1 %equal
; CHECK-NEXT: ret i1 false
@@ -56,9 +57,9 @@
define i1 @gep4() {
; CHECK: @gep4
- %x = alloca %t, align 8
- %a = getelementptr %t* @y, i64 0, i32 0
- %b = getelementptr %t* @y, i64 0, i32 1
+ %x = alloca %gept, align 8
+ %a = getelementptr %gept* @gepy, i64 0, i32 0
+ %b = getelementptr %gept* @gepy, i64 0, i32 1
%equal = icmp eq i32* %a, %b
ret i1 %equal
; CHECK-NEXT: ret i1 false
@@ -66,24 +67,33 @@
define i1 @gep5() {
; CHECK: @gep5
- %x = alloca %t, align 8
- %a = getelementptr inbounds %t* %x, i64 0, i32 1
- %b = getelementptr %t* @y, i64 0, i32 0
+ %x = alloca %gept, align 8
+ %a = getelementptr inbounds %gept* %x, i64 0, i32 1
+ %b = getelementptr %gept* @gepy, i64 0, i32 0
%equal = icmp eq i32* %a, %b
ret i1 %equal
; CHECK-NEXT: ret i1 false
}
-define i1 @gep6(%t* %x) {
+define i1 @gep6(%gept* %x) {
; Same as @gep3 but potentially null.
; CHECK: @gep6
- %a = getelementptr %t* %x, i64 0, i32 0
- %b = getelementptr %t* %x, i64 0, i32 1
+ %a = getelementptr %gept* %x, i64 0, i32 0
+ %b = getelementptr %gept* %x, i64 0, i32 1
%equal = icmp eq i32* %a, %b
ret i1 %equal
; CHECK-NEXT: ret i1 false
}
+define i1 @gep7(%gept* %x) {
+; CHECK: @gep7
+ %a = getelementptr %gept* %x, i64 0, i32 0
+ %b = getelementptr %gept* @gepz, i64 0, i32 0
+ %equal = icmp eq i32* %a, %b
+ ret i1 %equal
+; CHECK: ret i1 %equal
+}
+
define i1 @zext(i32 %x) {
; CHECK: @zext
%e1 = zext i32 %x to i64
More information about the llvm-commits
mailing list