From 7cc86b4cc63ccb0d3117255a3b9b724c7f86f40f Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 17 Dec 2009 21:27:47 +0000 Subject: [PATCH] Make the ptrtoint comparison simplification work if one side is a global. llvm-svn: 91624 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 2 +- llvm/test/Transforms/InstCombine/cast_ptr.ll | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index c7359c4de762..2c73e7ae0fe8 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -6452,7 +6452,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // if (X) ... // For generality, we handle any zero-extension of any operand comparison // with a constant or another cast from the same type. - if (isa(Op1) || isa(Op1)) + if (isa(Op1) || isa(Op1)) if (Instruction *R = visitICmpInstWithCastAndCast(I)) return R; } diff --git a/llvm/test/Transforms/InstCombine/cast_ptr.ll b/llvm/test/Transforms/InstCombine/cast_ptr.ll index 6544e7d735a4..6a00e8397848 100644 --- a/llvm/test/Transforms/InstCombine/cast_ptr.ll +++ b/llvm/test/Transforms/InstCombine/cast_ptr.ll @@ -27,3 +27,12 @@ define i1 @test2(i8* %a, i8* %b) { ret i1 %r } +; These casts should also be folded away. +; CHECK: @test3 +; CHECK: icmp eq i8* %a, @global +@global = global i8 0 +define i1 @test3(i8* %a) { + %tmpa = ptrtoint i8* %a to i32 + %r = icmp eq i32 %tmpa, ptrtoint (i8* @global to i32) + ret i1 %r +}