-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SimplifyCFG] Treat extract oneuse(op.with.overflow),1
pattern as a single instruction
#128021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
73548cb
[SimplifyCFG] Treat umul + extract pattern as cheap single instruction
spaits 1fdcfde
Fix formatting
spaits d9ad295
Extend tests
spaits 9cccde2
Fix test case with the same pattern twice
spaits ab6bcb2
Add a comment in the code trying to explain the situation
spaits 0c9c7d8
Name values
spaits e7e50d4
Move test under RISC-V folder
spaits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
llvm/test/Transforms/SimplifyCFG/RISCV/umul-extract-pattern.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s | ||
target triple = "riscv64-unknown-unknown-elf" | ||
|
||
define i16 @basicScenario(i64 %x, i64 %y) { | ||
; CHECK-LABEL: @basicScenario( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[Y:%.*]], 0 | ||
; CHECK-NEXT: [[MUL:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[Y]], i64 [[X:%.*]]) | ||
; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { i64, i1 } [[MUL]], 1 | ||
; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[CMP_NOT]], i1 false, i1 [[MUL_OV]] | ||
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP0]] to i16 | ||
; CHECK-NEXT: ret i16 [[CONV]] | ||
; | ||
entry: | ||
%cmp.not = icmp eq i64 %y, 0 | ||
br i1 %cmp.not, label %land.end, label %land.rhs | ||
|
||
land.rhs: ; preds = %entry | ||
%mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %y, i64 %x) | ||
%mul.ov = extractvalue { i64, i1 } %mul, 1 | ||
br label %land.end | ||
|
||
land.end: ; preds = %land.rhs, %entry | ||
%result = phi i1 [ false, %entry ], [ %mul.ov, %land.rhs ] | ||
%conv = zext i1 %result to i16 | ||
ret i16 %conv | ||
} | ||
|
||
define i16 @samePatternTwice(i64 %x, i64 %y) { | ||
; CHECK-LABEL: @samePatternTwice( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[Y:%.*]], 0 | ||
; CHECK-NEXT: [[MUL:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[Y]], i64 [[X:%.*]]) | ||
; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { i64, i1 } [[MUL]], 1 | ||
; CHECK-NEXT: [[MUL2:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[Y]], i64 [[X]]) | ||
; CHECK-NEXT: [[MUL_OV2:%.*]] = extractvalue { i64, i1 } [[MUL2]], 1 | ||
; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[CMP_NOT]], i1 false, i1 [[MUL_OV]] | ||
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[CMP_NOT]], i1 false, i1 [[MUL_OV2]] | ||
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP0]] to i16 | ||
; CHECK-NEXT: [[CONV2:%.*]] = zext i1 [[TMP1]] to i16 | ||
; CHECK-NEXT: [[TORET:%.*]] = add nsw i16 [[CONV]], [[CONV2]] | ||
; CHECK-NEXT: ret i16 [[TORET]] | ||
; | ||
entry: | ||
%cmp.not = icmp eq i64 %y, 0 | ||
br i1 %cmp.not, label %land.end, label %land.rhs | ||
|
||
land.rhs: ; preds = %entry | ||
%mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %y, i64 %x) | ||
%mul.ov = extractvalue { i64, i1 } %mul, 1 | ||
%mul2 = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %y, i64 %x) | ||
%mul.ov2 = extractvalue { i64, i1 } %mul2, 1 | ||
br label %land.end | ||
|
||
land.end: ; preds = %land.rhs, %entry | ||
%result1 = phi i1 [ false, %entry ], [ %mul.ov, %land.rhs ] | ||
%result2 = phi i1 [ false, %entry ], [ %mul.ov2, %land.rhs ] | ||
%conv1 = zext i1 %result1 to i16 | ||
%conv2 = zext i1 %result2 to i16 | ||
%toRet = add nsw i16 %conv1, %conv2 | ||
ret i16 %toRet | ||
} | ||
|
||
define i16 @stillHoistNotTooExpensive(i64 %x, i64 %y) { | ||
; CHECK-LABEL: @stillHoistNotTooExpensive( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[Y:%.*]], 0 | ||
; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[Y]], [[X:%.*]] | ||
; CHECK-NEXT: [[MUL:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[ADD]], i64 [[X]]) | ||
; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { i64, i1 } [[MUL]], 1 | ||
; CHECK-NEXT: [[TMP0:%.*]] = select i1 [[CMP_NOT]], i1 false, i1 [[MUL_OV]] | ||
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP0]] to i16 | ||
; CHECK-NEXT: ret i16 [[CONV]] | ||
; | ||
entry: | ||
%cmp.not = icmp eq i64 %y, 0 | ||
br i1 %cmp.not, label %land.end, label %land.rhs | ||
|
||
land.rhs: ; preds = %entry | ||
%add = add nsw i64 %y, %x | ||
%mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %add, i64 %x) | ||
%mul.ov = extractvalue { i64, i1 } %mul, 1 | ||
br label %land.end | ||
|
||
land.end: ; preds = %land.rhs, %entry | ||
%result = phi i1 [ false, %entry ], [ %mul.ov, %land.rhs ] | ||
%conv = zext i1 %result to i16 | ||
ret i16 %conv | ||
} | ||
|
||
define i16 @noHoistTooExpensive(i64 %x, i64 %y) { | ||
; CHECK-LABEL: @noHoistTooExpensive( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[Y:%.*]], 0 | ||
; CHECK-NEXT: br i1 [[CMP_NOT]], label [[LAND_END:%.*]], label [[LAND_RHS:%.*]] | ||
; CHECK: land.rhs: | ||
; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[Y]], [[X:%.*]] | ||
; CHECK-NEXT: [[ADD2:%.*]] = add nsw i64 [[Y]], [[ADD]] | ||
; CHECK-NEXT: [[ADD3:%.*]] = add nsw i64 [[ADD]], [[ADD2]] | ||
; CHECK-NEXT: [[ADD4:%.*]] = add nsw i64 [[ADD2]], [[ADD3]] | ||
; CHECK-NEXT: [[ADD5:%.*]] = add nsw i64 [[ADD3]], [[ADD4]] | ||
; CHECK-NEXT: [[MUL:%.*]] = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 [[ADD5]], i64 [[X]]) | ||
; CHECK-NEXT: [[MUL_OV:%.*]] = extractvalue { i64, i1 } [[MUL]], 1 | ||
; CHECK-NEXT: br label [[LAND_END]] | ||
; CHECK: land.end: | ||
; CHECK-NEXT: [[TMP0:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[MUL_OV]], [[LAND_RHS]] ] | ||
; CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP0]] to i16 | ||
; CHECK-NEXT: ret i16 [[CONV]] | ||
; | ||
entry: | ||
%cmp.not = icmp eq i64 %y, 0 | ||
br i1 %cmp.not, label %land.end, label %land.rhs | ||
|
||
land.rhs: ; preds = %entry | ||
%add = add nsw i64 %y, %x | ||
%add2 = add nsw i64 %y, %add | ||
%add3 = add nsw i64 %add, %add2 | ||
%add4 = add nsw i64 %add2, %add3 | ||
%add5 = add nsw i64 %add3, %add4 | ||
%mul = tail call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %add5, i64 %x) | ||
%mul.ov = extractvalue { i64, i1 } %mul, 1 | ||
br label %land.end | ||
|
||
land.end: ; preds = %land.rhs, %entry | ||
%result = phi i1 [ false, %entry ], [ %mul.ov, %land.rhs ] | ||
%conv = zext i1 %result to i16 | ||
ret i16 %conv | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.