-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Use InstSimplify in FoldOpIntoSelect #116073
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,14 +56,9 @@ define void @test_select_agg_multiuse(i1 %cond, i64 %v1, i64 %v2, i64 %v3, i64 % | |
; CHECK-LABEL: define void @test_select_agg_multiuse( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also add the tests from #115969? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I committed the extra tests in 3369424 and rebased this PR. |
||
; CHECK-SAME: i1 [[COND:%.*]], i64 [[V1:%.*]], i64 [[V2:%.*]], i64 [[V3:%.*]], i64 [[V4:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[A0:%.*]] = insertvalue { i64, i64 } poison, i64 [[V1]], 0 | ||
; CHECK-NEXT: [[A1:%.*]] = insertvalue { i64, i64 } [[A0]], i64 [[V2]], 1 | ||
; CHECK-NEXT: [[B0:%.*]] = insertvalue { i64, i64 } poison, i64 [[V3]], 0 | ||
; CHECK-NEXT: [[B1:%.*]] = insertvalue { i64, i64 } [[B0]], i64 [[V4]], 1 | ||
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND]], { i64, i64 } [[A1]], { i64, i64 } [[B1]] | ||
; CHECK-NEXT: [[X:%.*]] = extractvalue { i64, i64 } [[SEL]], 0 | ||
; CHECK-NEXT: [[X:%.*]] = select i1 [[COND]], i64 [[V1]], i64 [[V3]] | ||
; CHECK-NEXT: call void @use(i64 [[X]]) | ||
; CHECK-NEXT: [[Y:%.*]] = extractvalue { i64, i64 } [[SEL]], 1 | ||
; CHECK-NEXT: [[Y:%.*]] = select i1 [[COND]], i64 [[V2]], i64 [[V4]] | ||
; CHECK-NEXT: call void @use(i64 [[Y]]) | ||
; CHECK-NEXT: ret void | ||
; | ||
|
@@ -88,10 +83,8 @@ define i64 @test_extract_select_insert_left(ptr %p1, i64 %v) { | |
; CHECK-NEXT: [[CALL:%.*]] = call { ptr, i64 } @foo() | ||
; CHECK-NEXT: [[ELM1:%.*]] = extractvalue { ptr, i64 } [[CALL]], 1 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[ELM1]], [[V]] | ||
; CHECK-NEXT: [[FCA0:%.*]] = insertvalue { ptr, i64 } poison, ptr [[P1]], 0 | ||
; CHECK-NEXT: [[FCA1:%.*]] = insertvalue { ptr, i64 } [[FCA0]], i64 4294967294, 1 | ||
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], { ptr, i64 } [[FCA1]], { ptr, i64 } [[CALL]] | ||
; CHECK-NEXT: [[RES:%.*]] = extractvalue { ptr, i64 } [[SELECT]], 1 | ||
; CHECK-NEXT: [[TMP1:%.*]] = extractvalue { ptr, i64 } [[CALL]], 1 | ||
; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i64 4294967294, i64 [[TMP1]] | ||
; CHECK-NEXT: ret i64 [[RES]] | ||
; | ||
%call = call { ptr, i64 } @foo() | ||
|
@@ -110,10 +103,8 @@ define i64 @test_extract_select_insert_right(ptr %p1, i64 %v) { | |
; CHECK-NEXT: [[CALL:%.*]] = call { ptr, i64 } @foo() | ||
; CHECK-NEXT: [[ELM1:%.*]] = extractvalue { ptr, i64 } [[CALL]], 1 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[ELM1]], [[V]] | ||
; CHECK-NEXT: [[FCA0:%.*]] = insertvalue { ptr, i64 } poison, ptr [[P1]], 0 | ||
; CHECK-NEXT: [[FCA1:%.*]] = insertvalue { ptr, i64 } [[FCA0]], i64 4294967294, 1 | ||
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], { ptr, i64 } [[CALL]], { ptr, i64 } [[FCA1]] | ||
; CHECK-NEXT: [[RES:%.*]] = extractvalue { ptr, i64 } [[SELECT]], 1 | ||
; CHECK-NEXT: [[TMP1:%.*]] = extractvalue { ptr, i64 } [[CALL]], 1 | ||
; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i64 [[TMP1]], i64 4294967294 | ||
; CHECK-NEXT: ret i64 [[RES]] | ||
; | ||
%call = call { ptr, i64 } @foo() | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -52,7 +52,7 @@ define <2 x half> @fmul_constant_op1(<2 x float> %x) { | |||||||||||||||||||||||||||||||||||||
define float @fptrunc_select_true_val(float %x, double %y, i1 %cond) { | ||||||||||||||||||||||||||||||||||||||
; CHECK-LABEL: @fptrunc_select_true_val( | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc double [[Y:%.*]] to float | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[NARROW_SEL:%.*]] = select fast i1 [[COND:%.*]], float [[TMP1]], float [[X:%.*]] | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[NARROW_SEL:%.*]] = select i1 [[COND:%.*]], float [[TMP1]], float [[X:%.*]] | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was previously handled by llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp Lines 1870 to 1887 in 2ca25ab
However, I don't think that FMF preservation is actually correct. Let's say y is a big double and the fptrunc of it results in INF. Then we will violate ninf while we did not before. I think we should drop that separate fold after this PR lands. |
||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: ret float [[NARROW_SEL]] | ||||||||||||||||||||||||||||||||||||||
; | ||||||||||||||||||||||||||||||||||||||
%e = fpext float %x to double | ||||||||||||||||||||||||||||||||||||||
|
@@ -64,7 +64,7 @@ define float @fptrunc_select_true_val(float %x, double %y, i1 %cond) { | |||||||||||||||||||||||||||||||||||||
define <2 x float> @fptrunc_select_false_val(<2 x float> %x, <2 x double> %y, <2 x i1> %cond) { | ||||||||||||||||||||||||||||||||||||||
; CHECK-LABEL: @fptrunc_select_false_val( | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc <2 x double> [[Y:%.*]] to <2 x float> | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[NARROW_SEL:%.*]] = select nnan <2 x i1> [[COND:%.*]], <2 x float> [[X:%.*]], <2 x float> [[TMP1]] | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[NARROW_SEL:%.*]] = select <2 x i1> [[COND:%.*]], <2 x float> [[X:%.*]], <2 x float> [[TMP1]] | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: ret <2 x float> [[NARROW_SEL]] | ||||||||||||||||||||||||||||||||||||||
; | ||||||||||||||||||||||||||||||||||||||
%e = fpext <2 x float> %x to <2 x double> | ||||||||||||||||||||||||||||||||||||||
|
@@ -80,7 +80,7 @@ define half @fptrunc_select_true_val_extra_use(half %x, float %y, i1 %cond) { | |||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[E:%.*]] = fpext half [[X:%.*]] to float | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: call void @use(float [[E]]) | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[TMP1:%.*]] = fptrunc float [[Y:%.*]] to half | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[NARROW_SEL:%.*]] = select ninf i1 [[COND:%.*]], half [[TMP1]], half [[X]] | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: [[NARROW_SEL:%.*]] = select i1 [[COND:%.*]], half [[TMP1]], half [[X]] | ||||||||||||||||||||||||||||||||||||||
; CHECK-NEXT: ret half [[NARROW_SEL]] | ||||||||||||||||||||||||||||||||||||||
; | ||||||||||||||||||||||||||||||||||||||
%e = fpext half %x to float | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider this test:
If we insert the umin clone before the select, it still uses
%y.ext
, which is only defined after the select, so we get a verifier error. Inserting the instruction at the same position as the old one makes sure that we don't violate the dominance requirement.I believe this previously wasn't an issue because the transform would bail out anyway if the non-select operands were non-constant, so we didn't run into the problem.