From 6935aefdf0fdfd2641ebb27dd3b1aa6e5e2fe4ab Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Mon, 1 May 2017 23:12:08 +0000 Subject: [InstSimplify] Handle selects of GEPs with 0 offset In particular (since it wouldn't fit nicely in the summary): (select (icmp eq V 0) P (getelementptr P V)) -> (getelementptr P V) Differential Revision: https://reviews.llvm.org/D31435 llvm-svn: 301880 --- llvm/test/Transforms/InstSimplify/select.ll | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'llvm/test/Transforms/InstSimplify/select.ll') diff --git a/llvm/test/Transforms/InstSimplify/select.ll b/llvm/test/Transforms/InstSimplify/select.ll index cb2502cf63c..3e1af8c09b7 100644 --- a/llvm/test/Transforms/InstSimplify/select.ll +++ b/llvm/test/Transforms/InstSimplify/select.ll @@ -431,3 +431,22 @@ define i8 @do_not_assume_sel_cond(i1 %cond, i8 %x, i8 %y) { ret i8 %sel } +define i32* @select_icmp_eq_0_gep_operand(i32* %base, i64 %n) { +; CHECK-LABEL: @select_icmp_eq_0_gep_operand( +; CHECK-NEXT: [[GEP:%.*]] = getelementptr +; CHECK-NEXT: ret i32* [[GEP]] + %cond = icmp eq i64 %n, 0 + %gep = getelementptr i32, i32* %base, i64 %n + %r = select i1 %cond, i32* %base, i32* %gep + ret i32* %r +} + +define i32* @select_icmp_ne_0_gep_operand(i32* %base, i64 %n) { +; CHECK-LABEL: @select_icmp_ne_0_gep_operand( +; CHECK-NEXT: [[GEP:%.*]] = getelementptr +; CHECK-NEXT: ret i32* [[GEP]] + %cond = icmp ne i64 %n, 0 + %gep = getelementptr i32, i32* %base, i64 %n + %r = select i1 %cond, i32* %gep, i32* %base + ret i32* %r +} -- cgit v1.2.3