1; RUN: opt -march=hexagon -hexagon-loop-idiom -S < %s | FileCheck %s 2; CHECK-LABEL: define void @fred 3 4; Check that this test does not crash. 5 6target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048" 7target triple = "hexagon" 8 9%struct.0 = type { [120 x i16], [80 x i16], [80 x i16], [80 x i16], [80 x i16], [80 x i16], [40 x i16], [40 x i16], [40 x i16], [40 x i16], [40 x i16], [40 x i16] } 10 11define void @fred(%struct.0* %demod_state) local_unnamed_addr #0 { 12entry: 13 br label %for.body309 14 15for.body309: ; preds = %for.body309, %entry 16 %max_diff.0300 = phi i16 [ %max_diff.1, %for.body309 ], [ 0, %entry ] 17 %arrayidx322.phi = phi i16* [ undef, %entry ], [ %arrayidx322.inc, %for.body309 ] 18 %arrayidx331.phi = phi i16* [ undef, %entry ], [ %arrayidx331.inc, %for.body309 ] 19 %lag.4299.apmt = phi i32 [ %inc376.apmt, %for.body309 ], [ 0, %entry ] 20 %0 = load i16, i16* %arrayidx322.phi, align 2 21 %conv323 = sext i16 %0 to i32 22 %sub324 = sub nsw i32 0, %conv323 23 %ispos258 = icmp sgt i32 %sub324, -1 24 %1 = select i1 %ispos258, i32 %sub324, i32 0 25 %add326 = add nsw i32 %1, 0 26 %2 = load i16, i16* %arrayidx331.phi, align 2 27 %conv332 = sext i16 %2 to i32 28 %sub333 = sub nsw i32 0, %conv332 29 %ispos260 = icmp sgt i32 %sub333, -1 30 %3 = select i1 %ispos260, i32 %sub333, i32 undef 31 %sub342 = sub nsw i32 0, %conv323 32 %ispos262 = icmp sgt i32 %sub342, -1 33 %4 = select i1 %ispos262, i32 %sub342, i32 undef 34 %sub351 = sub nsw i32 0, %conv332 35 %ispos264 = icmp sgt i32 %sub351, -1 36 %5 = select i1 %ispos264, i32 %sub351, i32 0 37 %sub360 = sub nsw i32 %conv323, %conv332 38 %ispos266 = icmp sgt i32 %sub360, -1 39 %6 = select i1 %ispos266, i32 %sub360, i32 0 40 %add335 = add nsw i32 %add326, %4 41 %add344 = add nsw i32 %add335, %3 42 %add353 = add i32 %add344, %5 43 %add362 = add i32 %add353, %6 44 %div363 = sdiv i32 %add362, 6 45 %conv364 = trunc i32 %div363 to i16 46 %sext268 = shl i32 %div363, 16 47 %conv369 = ashr exact i32 %sext268, 16 48 %conv370 = sext i16 %max_diff.0300 to i32 49 %cmp371 = icmp sgt i32 %conv369, %conv370 50 %max_diff.1 = select i1 %cmp371, i16 %conv364, i16 %max_diff.0300 51 %inc376.apmt = add nuw nsw i32 %lag.4299.apmt, 1 52 %exitcond331 = icmp ne i32 %inc376.apmt, 40 53 %arrayidx322.inc = getelementptr i16, i16* %arrayidx322.phi, i32 1 54 %arrayidx331.inc = getelementptr i16, i16* %arrayidx331.phi, i32 1 55 br i1 %exitcond331, label %for.body309, label %for.end377 56 57for.end377: ; preds = %for.body309 58 %max_diff.1.lcssa = phi i16 [ %max_diff.1, %for.body309 ] 59 %cmp407 = icmp sgt i16 %max_diff.1.lcssa, 4 60 br label %for.body405 61 62for.body405: ; preds = %if.end437, %for.end377 63 %arrayidx412 = getelementptr inbounds %struct.0, %struct.0* %demod_state, i32 0, i32 11, i32 undef 64 br i1 %cmp407, label %if.then409, label %if.end437 65 66if.then409: ; preds = %for.body405 67 %arrayidx416 = getelementptr inbounds [40 x i16], [40 x i16]* null, i32 0, i32 undef 68 %7 = load i16, i16* %arrayidx416, align 2 69 %conv417 = sext i16 %7 to i32 70 %shl = shl i32 %conv417, 4 71 %mul419 = mul nsw i32 %shl, 655 72 %add420 = add nsw i32 %mul419, 0 73 br label %if.end437 74 75if.end437: ; preds = %if.then409, %for.body405 76 %mul431.sink = phi i32 [ %add420, %if.then409 ], [ undef, %for.body405 ] 77 %shr432257 = lshr i32 %mul431.sink, 15 78 %conv433 = trunc i32 %shr432257 to i16 79 store i16 %conv433, i16* %arrayidx412, align 2 80 br label %for.body405 81} 82 83attributes #0 = { noinline nounwind "target-cpu"="hexagonv60" "target-features"="-hvx,-long-calls" } 84