From 9004c8afd4bf7b3f27f4a4f8fd069379afa97c83 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 21 May 2009 02:28:33 +0000 Subject: Teach ValueTracking a new way to analyze PHI nodes, and and teach Instcombine to be more aggressive about using SimplifyDemandedBits on shift nodes. This allows a shift to be simplified to zero in the included test case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72204 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/lshr-phi.ll | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/Transforms/InstCombine/lshr-phi.ll (limited to 'test/Transforms/InstCombine/lshr-phi.ll') diff --git a/test/Transforms/InstCombine/lshr-phi.ll b/test/Transforms/InstCombine/lshr-phi.ll new file mode 100644 index 0000000000..683eb87931 --- /dev/null +++ b/test/Transforms/InstCombine/lshr-phi.ll @@ -0,0 +1,35 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis > %t +; RUN: not grep lshr %t +; RUN: grep add %t | count 1 + +; Instcombine should be able to eliminate the lshr, because only +; bits in the operand which might be non-zero will be shifted +; off the end. + +define i32 @hash_string(i8* nocapture %key) nounwind readonly { +entry: + %t0 = load i8* %key, align 1 ; [#uses=1] + %t1 = icmp eq i8 %t0, 0 ; [#uses=1] + br i1 %t1, label %bb2, label %bb + +bb: ; preds = %bb, %entry + %indvar = phi i64 [ 0, %entry ], [ %tmp, %bb ] ; [#uses=2] + %k.04 = phi i32 [ 0, %entry ], [ %t8, %bb ] ; [#uses=2] + %cp.05 = getelementptr i8* %key, i64 %indvar ; [#uses=1] + %t2 = shl i32 %k.04, 1 ; [#uses=1] + %t3 = lshr i32 %k.04, 14 ; [#uses=1] + %t4 = add i32 %t2, %t3 ; [#uses=1] + %t5 = load i8* %cp.05, align 1 ; [#uses=1] + %t6 = sext i8 %t5 to i32 ; [#uses=1] + %t7 = xor i32 %t6, %t4 ; [#uses=1] + %t8 = and i32 %t7, 16383 ; [#uses=2] + %tmp = add i64 %indvar, 1 ; [#uses=2] + %scevgep = getelementptr i8* %key, i64 %tmp ; [#uses=1] + %t9 = load i8* %scevgep, align 1 ; [#uses=1] + %t10 = icmp eq i8 %t9, 0 ; [#uses=1] + br i1 %t10, label %bb2, label %bb + +bb2: ; preds = %bb, %entry + %k.0.lcssa = phi i32 [ 0, %entry ], [ %t8, %bb ] ; [#uses=1] + ret i32 %k.0.lcssa +} -- cgit v1.2.3