File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
test/Transforms/TypePromotion/AArch64 Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -569,7 +569,8 @@ void IRPromoter::TruncateSinks() {
569569void IRPromoter::Cleanup () {
570570 LLVM_DEBUG (dbgs () << " IR Promotion: Cleanup..\n " );
571571 // Some zexts will now have become redundant, along with their trunc
572- // operands, so remove them
572+ // operands, so remove them.
573+ // Some zexts need to be replaced with truncate if src bitwidth is larger.
573574 for (auto *V : Visited) {
574575 if (!isa<ZExtInst>(V))
575576 continue ;
@@ -584,6 +585,11 @@ void IRPromoter::Cleanup() {
584585 << " \n " );
585586 ReplaceAllUsersOfWith (ZExt, Src);
586587 continue ;
588+ } else if (ZExt->getSrcTy ()->getScalarSizeInBits () > PromotedWidth) {
589+ IRBuilder<> Builder{ZExt};
590+ Value *Trunc = Builder.CreateTrunc (Src, ZExt->getDestTy ());
591+ ReplaceAllUsersOfWith (ZExt, Trunc);
592+ continue ;
587593 }
588594
589595 // We've inserted a trunc for a zext sink, but we already know that the
Original file line number Diff line number Diff line change 1+ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+ ; RUN: opt -mtriple=aarch64 -type-promotion -verify -S %s -o - | FileCheck %s
3+ target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4+
5+ ; Check the case don't crash due to zext source type bitwidth
6+ ; larger than dest type bitwidth.
7+ define i1 @test (i8 %arg ) {
8+ ; CHECK-LABEL: @test(
9+ ; CHECK-NEXT: [[EXT1:%.*]] = zext i8 [[ARG:%.*]] to i64
10+ ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[EXT1]], 7
11+ ; CHECK-NEXT: [[TMP2:%.*]] = trunc i64 [[TMP1]] to i32
12+ ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[TMP2]], 0
13+ ; CHECK-NEXT: ret i1 [[CMP]]
14+ ;
15+ %ext1 = zext i8 %arg to i64
16+ %trunc = trunc i64 %ext1 to i3
17+ %ext2 = zext i3 %trunc to i8
18+ %cmp = icmp ne i8 %ext2 , 0
19+ ret i1 %cmp
20+ }
You can’t perform that action at this time.
0 commit comments