Skip to content

Commit 09b1cfc

Browse files
committed
[InstCombine] Add additional test case for (add (zext (add nuw X, C2), C1). NFC
Add test where the zext has an additional use, but the entire expression can be replaced with (zext X). Folding even though there is an additional use would not increase the number of instructions.
1 parent 05f9877 commit 09b1cfc

File tree

1 file changed

+15
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+15
-0
lines changed

llvm/test/Transforms/InstCombine/add.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,21 @@ define i64 @test41(i32 %a) {
951951
ret i64 %sub
952952
}
953953

954+
define i64 @test41_multiuse_constants_cancel(i32 %a) {
955+
; CHECK-LABEL: @test41_multiuse_constants_cancel(
956+
; CHECK-NEXT: [[ADD:%.*]] = add nuw i32 [[A:%.*]], 1
957+
; CHECK-NEXT: [[ZEXT:%.*]] = zext i32 [[ADD]] to i64
958+
; CHECK-NEXT: [[REASS_ADD:%.*]] = shl nuw nsw i64 [[ZEXT]], 1
959+
; CHECK-NEXT: [[EXTRAUSE:%.*]] = add nsw i64 [[REASS_ADD]], -1
960+
; CHECK-NEXT: ret i64 [[EXTRAUSE]]
961+
;
962+
%add = add nuw i32 %a, 1
963+
%zext = zext i32 %add to i64
964+
%sub = add i64 %zext, -1
965+
%extrause = add i64 %zext, %sub
966+
ret i64 %extrause
967+
}
968+
954969
; (add (zext (add nuw X, C2)), C) --> (zext (add nuw X, C2 + C))
955970

956971
define <2 x i64> @test41vec(<2 x i32> %a) {

0 commit comments

Comments
 (0)