Files
TheRock/compiler/amd-llvm/llvm/test/Transforms/ConstraintElimination/trunc.ll
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

371 lines
11 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
define i1 @test_icmp_ult_zext_icmp_trunc_nuw(i16 %x, i32 %y) {
; CHECK-LABEL: define i1 @test_icmp_ult_zext_icmp_trunc_nuw(
; CHECK-SAME: i16 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[EXT:%.*]] = zext i16 [[X]] to i32
; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[Y]], [[EXT]]
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[CONV:%.*]] = trunc nuw i32 [[Y]] to i16
; CHECK-NEXT: ret i1 false
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%ext = zext i16 %x to i32
%cond = icmp ult i32 %y, %ext
br i1 %cond, label %if.then, label %if.else
if.then:
%conv = trunc nuw i32 %y to i16
%cmp = icmp eq i16 %x, %conv
ret i1 %cmp
if.else:
ret i1 false
}
define i1 @test_icmp_slt_sext_icmp_trunc_nsw(i16 %x, i32 %y) {
; CHECK-LABEL: define i1 @test_icmp_slt_sext_icmp_trunc_nsw(
; CHECK-SAME: i16 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[EXT:%.*]] = sext i16 [[X]] to i32
; CHECK-NEXT: [[COND:%.*]] = icmp slt i32 [[Y]], [[EXT]]
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[CONV:%.*]] = trunc nsw i32 [[Y]] to i16
; CHECK-NEXT: ret i1 false
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%ext = sext i16 %x to i32
%cond = icmp slt i32 %y, %ext
br i1 %cond, label %if.then, label %if.else
if.then:
%conv = trunc nsw i32 %y to i16
%cmp = icmp slt i16 %x, %conv
ret i1 %cmp
if.else:
ret i1 false
}
define i1 @test_icmp_ult_trunc_nsw_nneg_icmp_trunc_nuw(i64 %x, i32 %y) {
; CHECK-LABEL: define i1 @test_icmp_ult_trunc_nsw_nneg_icmp_trunc_nuw(
; CHECK-SAME: i64 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[EXT:%.*]] = trunc nsw i64 [[X]] to i32
; CHECK-NEXT: [[NNEG:%.*]] = icmp sgt i64 [[X]], -1
; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[Y]], [[EXT]]
; CHECK-NEXT: [[AND:%.*]] = and i1 [[NNEG]], [[COND]]
; CHECK-NEXT: br i1 [[AND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[CONV:%.*]] = zext i32 [[Y]] to i64
; CHECK-NEXT: ret i1 false
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%ext = trunc nsw i64 %x to i32
%nneg = icmp sgt i64 %x, -1
%cond = icmp ult i32 %y, %ext
%and = and i1 %nneg, %cond
br i1 %and, label %if.then, label %if.else
if.then:
%conv = zext i32 %y to i64
%cmp = icmp eq i64 %x, %conv
ret i1 %cmp
if.else:
ret i1 false
}
define i1 @test2(i32 %n) {
; CHECK-LABEL: define i1 @test2(
; CHECK-SAME: i32 [[N:%.*]]) {
; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[N]], 0
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[EXT:%.*]] = zext nneg i32 [[N]] to i64
; CHECK-NEXT: [[END:%.*]] = add nsw i64 [[EXT]], -1
; CHECK-NEXT: br label %[[FOR_BODY:.*]]
; CHECK: [[FOR_BODY]]:
; CHECK-NEXT: [[INDVAR:%.*]] = phi i64 [ 0, %[[IF_THEN]] ], [ [[INDVAR_NEXT:%.*]], %[[FOR_NEXT:.*]] ]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[INDVAR]], [[END]]
; CHECK-NEXT: br i1 [[CMP]], label %[[IF_ELSE]], label %[[FOR_NEXT]]
; CHECK: [[FOR_NEXT]]:
; CHECK-NEXT: [[INDVAR_NEXT]] = add nuw nsw i64 [[INDVAR]], 1
; CHECK-NEXT: [[COND2:%.*]] = call i1 @cond()
; CHECK-NEXT: br i1 [[COND2]], label %[[FOR_BODY]], label %[[FOR_END:.*]]
; CHECK: [[FOR_END]]:
; CHECK-NEXT: [[TRUNC:%.*]] = trunc nsw i64 [[INDVAR_NEXT]] to i32
; CHECK-NEXT: ret i1 true
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%cond = icmp sgt i32 %n, 0
br i1 %cond, label %if.then, label %if.else
if.then:
%ext = zext nneg i32 %n to i64
%end = add nsw i64 %ext, -1
br label %for.body
for.body:
%indvar = phi i64 [ 0, %if.then ], [ %indvar.next, %for.next ]
%cmp = icmp eq i64 %indvar, %end
br i1 %cmp, label %if.else, label %for.next
for.next:
%indvar.next = add nuw nsw i64 %indvar, 1
%cond2 = call i1 @cond()
br i1 %cond2, label %for.body, label %for.end
for.end:
%trunc = trunc nsw i64 %indvar.next to i32
%res = icmp sgt i32 %n, %trunc
ret i1 %res
if.else:
ret i1 false
}
define i1 @test_icmp_ult_zext_icmp_trunc(i16 %x, i32 %y) {
; CHECK-LABEL: define i1 @test_icmp_ult_zext_icmp_trunc(
; CHECK-SAME: i16 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[EXT:%.*]] = zext i16 [[X]] to i32
; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[Y]], [[EXT]]
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[CONV:%.*]] = trunc i32 [[Y]] to i16
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[X]], [[CONV]]
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%ext = zext i16 %x to i32
%cond = icmp ult i32 %y, %ext
br i1 %cond, label %if.then, label %if.else
if.then:
%conv = trunc i32 %y to i16
%cmp = icmp eq i16 %x, %conv
ret i1 %cmp
if.else:
ret i1 false
}
define i1 @test_icmp_ult_zext_icmp_trunc_nuw_i128(i16 %x, i128 %y) {
; CHECK-LABEL: define i1 @test_icmp_ult_zext_icmp_trunc_nuw_i128(
; CHECK-SAME: i16 [[X:%.*]], i128 [[Y:%.*]]) {
; CHECK-NEXT: [[EXT:%.*]] = zext i16 [[X]] to i128
; CHECK-NEXT: [[COND:%.*]] = icmp ult i128 [[Y]], [[EXT]]
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[CONV:%.*]] = trunc nuw i128 [[Y]] to i16
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[X]], [[CONV]]
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%ext = zext i16 %x to i128
%cond = icmp ult i128 %y, %ext
br i1 %cond, label %if.then, label %if.else
if.then:
%conv = trunc nuw i128 %y to i16
%cmp = icmp eq i16 %x, %conv
ret i1 %cmp
if.else:
ret i1 false
}
; We do not know the sign of %x, so we cannot infer nuw for %ext.
define i1 @test_icmp_ult_trunc_nsw_icmp_trunc_nuw(i64 %x, i32 %y) {
; CHECK-LABEL: define i1 @test_icmp_ult_trunc_nsw_icmp_trunc_nuw(
; CHECK-SAME: i64 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: [[EXT:%.*]] = trunc nsw i64 [[X]] to i32
; CHECK-NEXT: [[COND:%.*]] = icmp ult i32 [[Y]], [[EXT]]
; CHECK-NEXT: br i1 [[COND]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
; CHECK: [[IF_THEN]]:
; CHECK-NEXT: [[CONV:%.*]] = zext i32 [[Y]] to i64
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[X]], [[CONV]]
; CHECK-NEXT: ret i1 [[CMP]]
; CHECK: [[IF_ELSE]]:
; CHECK-NEXT: ret i1 false
;
%ext = trunc nsw i64 %x to i32
%cond = icmp ult i32 %y, %ext
br i1 %cond, label %if.then, label %if.else
if.then:
%conv = zext i32 %y to i64
%cmp = icmp eq i64 %x, %conv
ret i1 %cmp
if.else:
ret i1 false
}
define void @test_trunc_nuw(i1 %c, i8 %x) {
; CHECK-LABEL: define void @test_trunc_nuw(
; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[C_1:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: br i1 [[C_1]], label %[[BB1:.*]], label %[[EXIT:.*]]
; CHECK: [[BB1]]:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[T_3:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_3]])
; CHECK-NEXT: ret void
; CHECK: [[EXIT]]:
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[T_6:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_6]])
; CHECK-NEXT: ret void
;
entry:
%c.1 = trunc nuw i8 %x to i1
br i1 %c.1, label %if.then, label %if.else
if.then:
%t.1 = icmp eq i8 %x, 0
call void @use(i1 %t.1)
%t.2 = icmp ne i8 %x, 0
call void @use(i1 %t.2)
%t.3 = trunc nuw i8 %x to i1
call void @use(i1 %t.3)
ret void
if.else:
%t.4 = icmp eq i8 %x, 0
call void @use(i1 %t.4)
%t.5 = icmp ne i8 %x, 0
call void @use(i1 %t.5)
%t.6 = trunc nuw i8 %x to i1
call void @use(i1 %t.6)
ret void
}
define void @assume_trunc_nuw(i8 %x) {
; CHECK-LABEL: define void @assume_trunc_nuw(
; CHECK-SAME: i8 [[X:%.*]]) {
; CHECK-NEXT: [[C_1:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]])
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[T_3:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_3]])
; CHECK-NEXT: ret void
;
%c.1 = trunc nuw i8 %x to i1
call void @llvm.assume(i1 %c.1)
%t.1 = icmp eq i8 %x, 0
call void @use(i1 %t.1)
%t.2 = icmp ne i8 %x, 0
call void @use(i1 %t.2)
%t.3 = trunc nuw i8 %x to i1
call void @use(i1 %t.3)
ret void
}
define void @test_or_trunc_nuw(i1 %c, i8 %x) {
; CHECK-LABEL: define void @test_or_trunc_nuw(
; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[C_1:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: [[OR:%.*]] = or i1 [[C]], [[C_1]]
; CHECK-NEXT: br i1 [[OR]], label %[[BB1:.*]], label %[[EXIT:.*]]
; CHECK: [[BB1]]:
; CHECK-NEXT: [[T_1:%.*]] = icmp eq i8 [[X]], 0
; CHECK-NEXT: call void @use(i1 [[T_1]])
; CHECK-NEXT: [[T_2:%.*]] = icmp ne i8 [[X]], 0
; CHECK-NEXT: call void @use(i1 [[T_2]])
; CHECK-NEXT: [[T_3:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_3]])
; CHECK-NEXT: ret void
; CHECK: [[EXIT]]:
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: [[T_6:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_6]])
; CHECK-NEXT: ret void
;
entry:
%c.1 = trunc nuw i8 %x to i1
%or = or i1 %c, %c.1
br i1 %or, label %if.then, label %if.else
if.then:
%t.1 = icmp eq i8 %x, 0
call void @use(i1 %t.1)
%t.2 = icmp ne i8 %x, 0
call void @use(i1 %t.2)
%t.3 = trunc nuw i8 %x to i1
call void @use(i1 %t.3)
ret void
if.else:
%t.4 = icmp eq i8 %x, 0
call void @use(i1 %t.4)
%t.5 = icmp ne i8 %x, 0
call void @use(i1 %t.5)
%t.6 = trunc nuw i8 %x to i1
call void @use(i1 %t.6)
ret void
}
define void @test_and_trunc_nuw(i1 %c, i8 %x) {
; CHECK-LABEL: define void @test_and_trunc_nuw(
; CHECK-SAME: i1 [[C:%.*]], i8 [[X:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[C_1:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: [[AND:%.*]] = and i1 [[C]], [[C_1]]
; CHECK-NEXT: br i1 [[AND]], label %[[BB1:.*]], label %[[EXIT:.*]]
; CHECK: [[BB1]]:
; CHECK-NEXT: call void @use(i1 false)
; CHECK-NEXT: call void @use(i1 true)
; CHECK-NEXT: [[T_3:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_3]])
; CHECK-NEXT: ret void
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[T_4:%.*]] = icmp eq i8 [[X]], 0
; CHECK-NEXT: call void @use(i1 [[T_4]])
; CHECK-NEXT: [[T_5:%.*]] = icmp ne i8 [[X]], 0
; CHECK-NEXT: call void @use(i1 [[T_5]])
; CHECK-NEXT: [[T_6:%.*]] = trunc nuw i8 [[X]] to i1
; CHECK-NEXT: call void @use(i1 [[T_6]])
; CHECK-NEXT: ret void
;
entry:
%c.1 = trunc nuw i8 %x to i1
%and = and i1 %c, %c.1
br i1 %and, label %if.then, label %if.else
if.then:
%t.1 = icmp eq i8 %x, 0
call void @use(i1 %t.1)
%t.2 = icmp ne i8 %x, 0
call void @use(i1 %t.2)
%t.3 = trunc nuw i8 %x to i1
call void @use(i1 %t.3)
ret void
if.else:
%t.4 = icmp eq i8 %x, 0
call void @use(i1 %t.4)
%t.5 = icmp ne i8 %x, 0
call void @use(i1 %t.5)
%t.6 = trunc nuw i8 %x to i1
call void @use(i1 %t.6)
ret void
}
declare void @use(i1)
declare void @cond()