1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; Instcombine should be able to eliminate the lshr, because only
5 ; bits in the operand which might be non-zero will be shifted
8 define i32 @hash_string(i8* nocapture %key) nounwind readonly {
9 ; CHECK-LABEL: @hash_string(
11 ; CHECK-NEXT: [[T0:%.*]] = load i8, i8* [[KEY:%.*]], align 1
12 ; CHECK-NEXT: [[T1:%.*]] = icmp eq i8 [[T0]], 0
13 ; CHECK-NEXT: br i1 [[T1]], label [[BB2:%.*]], label [[BB:%.*]]
15 ; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[T:%.*]], [[BB]] ]
16 ; CHECK-NEXT: [[K_04:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[T8:%.*]], [[BB]] ]
17 ; CHECK-NEXT: [[CP_05:%.*]] = getelementptr i8, i8* [[KEY]], i64 [[INDVAR]]
18 ; CHECK-NEXT: [[T2:%.*]] = shl nuw nsw i32 [[K_04]], 1
19 ; CHECK-NEXT: [[T5:%.*]] = load i8, i8* [[CP_05]], align 1
20 ; CHECK-NEXT: [[T6:%.*]] = sext i8 [[T5]] to i32
21 ; CHECK-NEXT: [[T7:%.*]] = xor i32 [[T2]], [[T6]]
22 ; CHECK-NEXT: [[T8]] = and i32 [[T7]], 16383
23 ; CHECK-NEXT: [[T]] = add i64 [[INDVAR]], 1
24 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, i8* [[KEY]], i64 [[T]]
25 ; CHECK-NEXT: [[T9:%.*]] = load i8, i8* [[SCEVGEP]], align 1
26 ; CHECK-NEXT: [[T10:%.*]] = icmp eq i8 [[T9]], 0
27 ; CHECK-NEXT: br i1 [[T10]], label [[BB2]], label [[BB]]
29 ; CHECK-NEXT: [[K_0_LCSSA:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[T8]], [[BB]] ]
30 ; CHECK-NEXT: ret i32 [[K_0_LCSSA]]
33 %t0 = load i8, i8* %key, align 1
34 %t1 = icmp eq i8 %t0, 0
35 br i1 %t1, label %bb2, label %bb
38 %indvar = phi i64 [ 0, %entry ], [ %t, %bb ]
39 %k.04 = phi i32 [ 0, %entry ], [ %t8, %bb ]
40 %cp.05 = getelementptr i8, i8* %key, i64 %indvar
41 %t2 = shl i32 %k.04, 1
42 %t3 = lshr i32 %k.04, 14
43 %t4 = add i32 %t2, %t3
44 %t5 = load i8, i8* %cp.05, align 1
45 %t6 = sext i8 %t5 to i32
46 %t7 = xor i32 %t6, %t4
47 %t8 = and i32 %t7, 16383
48 %t = add i64 %indvar, 1
49 %scevgep = getelementptr i8, i8* %key, i64 %t
50 %t9 = load i8, i8* %scevgep, align 1
51 %t10 = icmp eq i8 %t9, 0
52 br i1 %t10, label %bb2, label %bb
55 %k.0.lcssa = phi i32 [ 0, %entry ], [ %t8, %bb ]