llvm.org GIT mirror llvm / fd8779a
InstSimplify: Ignore pointer casts when constant folding compares between pointers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150690 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 7 years ago
2 changed file(s) with 25 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
15901590 // to the case where LHS is a global variable address or null is pointless,
15911591 // since if both LHS and RHS are constants then we already constant folded
15921592 // the compare, and if only one of them is then we moved it to RHS already.
1593 if (isa(LHS) && (isa(RHS) || isa(RHS) ||
1594 isa(RHS)))
1593 Value *LHSPtr = LHS->stripPointerCasts();
1594 Value *RHSPtr = RHS->stripPointerCasts();
1595 if (isa(LHSPtr) && (isa(RHSPtr) ||
1596 isa(RHSPtr) ||
1597 isa(RHSPtr)))
15951598 // We already know that LHS != RHS.
15961599 return ConstantInt::get(ITy, CmpInst::isFalseWhenEqual(Pred));
15971600
77 %r = icmp eq i32 %tmp, 0
88 ret i1 %r
99 ; CHECK: ret i1 false
10 }
11
12 define i1 @bitcast() {
13 ; CHECK: @bitcast
14 %a = alloca i32
15 %b = alloca i64
16 %x = bitcast i32* %a to i8*
17 %y = bitcast i64* %b to i8*
18 %cmp = icmp eq i8* %x, %y
19 ret i1 %cmp
20 ; CHECK-NEXT: ret i1 false
21 }
22
23 define i1 @gep() {
24 ; CHECK: @gep
25 %a = alloca [3 x i8], align 8
26 %x = getelementptr inbounds [3 x i8]* %a, i32 0, i32 0
27 %cmp = icmp eq i8* %x, null
28 ret i1 %cmp
29 ; CHECK-NEXT: ret i1 false
1030 }
1131
1232 define i1 @zext(i32 %x) {