File: strlen-cleanup.ll

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,245,028 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,675; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (43 lines) | stat: -rw-r--r-- 2,192 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt < %s -S -passes=loop-idiom,loop-deletion | FileCheck %s

define [2 x i64] @convert_null_terminated_to_bounded_ptr(ptr noundef %p) {
; CHECK-LABEL: define [2 x i64] @convert_null_terminated_to_bounded_ptr(
; CHECK-SAME: ptr noundef [[P:%.*]]) {
; CHECK-NEXT:  [[ENTRY:.*:]]
; CHECK-NEXT:    [[WCSLEN:%.*]] = call i64 @wcslen(ptr [[P]])
; CHECK-NEXT:    br label %[[TERMINATED_BY_LOOP_END:.*]]
; CHECK:       [[TERMINATED_BY_LOOP_END]]:
; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 [[WCSLEN]]
; CHECK-NEXT:    [[TERMINATED_BY_UPPER:%.*]] = getelementptr i8, ptr [[TMP0]], i64 4
; CHECK-NEXT:    [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64
; CHECK-NEXT:    [[DOTFCA_0_INSERT:%.*]] = insertvalue [2 x i64] poison, i64 [[TMP1]], 0
; CHECK-NEXT:    [[TMP2:%.*]] = ptrtoint ptr [[TERMINATED_BY_UPPER]] to i64
; CHECK-NEXT:    [[DOTFCA_1_INSERT:%.*]] = insertvalue [2 x i64] [[DOTFCA_0_INSERT]], i64 [[TMP2]], 1
; CHECK-NEXT:    ret [2 x i64] [[DOTFCA_1_INSERT]]
;
entry:
  br label %terminated_by.loop_cond

terminated_by.loop_cond:                          ; preds = %terminated_by.loop_cond, %entry
  %terminated_by.len.0 = phi i64 [ 0, %entry ], [ %terminated_by.new_len, %terminated_by.loop_cond ]
  %0 = getelementptr inbounds i32, ptr %p, i64 %terminated_by.len.0
  %terminated_by.elem = load i32, ptr %0, align 4
  %terminted_by.check_terminator = icmp eq i32 %terminated_by.elem, 0
  %terminated_by.new_len = add i64 %terminated_by.len.0, 1
  br i1 %terminted_by.check_terminator, label %terminated_by.loop_end, label %terminated_by.loop_cond

terminated_by.loop_end:                           ; preds = %terminated_by.loop_cond
  %1 = getelementptr inbounds i32, ptr %p, i64 %terminated_by.len.0
  %terminated_by.upper = getelementptr i8, ptr %1, i64 4
  %2 = ptrtoint ptr %p to i64
  %.fca.0.insert = insertvalue [2 x i64] poison, i64 %2, 0
  %3 = ptrtoint ptr %terminated_by.upper to i64
  %.fca.1.insert = insertvalue [2 x i64] %.fca.0.insert, i64 %3, 1
  ret [2 x i64] %.fca.1.insert
}

!llvm.module.flags = !{!0}

!0 = !{i32 1, !"wchar_size", i32 4}