zhongyunde 34d380e1f6 [IndVars] Add check of loop invariant for indirect use
We usually only check direct use instruction of IV, while the
bitcast of 'ptrtoint ptr to i64' doesn't affect the result, so go
a step further.
Fix https://github.com/llvm/llvm-project/issues/59633.

Reviewed By: markoshorro
Differential Revision: https://reviews.llvm.org/D151877
2023-06-03 22:29:09 +08:00

30 lines
1.0 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=indvars -S | FileCheck %s
declare void @foo(i64 noundef)
; Function Attrs: mustprogress noreturn uwtable
define void @pr59633(ptr noundef %ptr) {
; CHECK-LABEL: @pr59633(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[PTR1:%.*]] = ptrtoint ptr [[PTR:%.*]] to i64
; CHECK-NEXT: [[TMP0:%.*]] = trunc i64 [[PTR1]] to i4
; CHECK-NEXT: [[TMP1:%.*]] = zext i4 [[TMP0]] to i64
; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
; CHECK: while.body:
; CHECK-NEXT: tail call void @foo(i64 noundef [[TMP1]])
; CHECK-NEXT: br label [[WHILE_BODY]]
;
entry:
br label %while.body
while.body: ; preds = %entry, %while.body
%ptr.addr.0 = phi ptr [ %ptr, %entry ], [ %add.ptr, %while.body ]
%0 = ptrtoint ptr %ptr.addr.0 to i64
%and = and i64 %0, 15 ; loop invariant
tail call void @foo(i64 noundef %and)
%add.ptr = getelementptr inbounds i8, ptr %ptr.addr.0, i64 16
br label %while.body
}