-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Remove redundant fptrunc of select fold (NFCI) #117182
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
Conversation
This was subsumed by FoldOpIntoSelect() in llvm#116073, and has incorrect FMF propagation on top.
@llvm/pr-subscribers-llvm-transforms Author: Nikita Popov (nikic) ChangesThis was subsumed by FoldOpIntoSelect() in #116073, and has incorrect FMF propagation on top. Full diff: https://github.com/llvm/llvm-project/pull/117182.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 6c2554ea73b7f8..c97be6ffc75675 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1866,24 +1866,6 @@ Instruction *InstCombinerImpl::visitFPTrunc(FPTruncInst &FPT) {
return UnaryOperator::CreateFNegFMF(InnerTrunc, Op);
}
-
- // If we are truncating a select that has an extended operand, we can
- // narrow the other operand and do the select as a narrow op.
- Value *Cond, *X, *Y;
- if (match(Op, m_Select(m_Value(Cond), m_FPExt(m_Value(X)), m_Value(Y))) &&
- X->getType() == Ty) {
- // fptrunc (select Cond, (fpext X), Y --> select Cond, X, (fptrunc Y)
- Value *NarrowY = Builder.CreateFPTrunc(Y, Ty);
- Value *Sel = Builder.CreateSelect(Cond, X, NarrowY, "narrow.sel", Op);
- return replaceInstUsesWith(FPT, Sel);
- }
- if (match(Op, m_Select(m_Value(Cond), m_Value(Y), m_FPExt(m_Value(X)))) &&
- X->getType() == Ty) {
- // fptrunc (select Cond, Y, (fpext X) --> select Cond, (fptrunc Y), X
- Value *NarrowY = Builder.CreateFPTrunc(Y, Ty);
- Value *Sel = Builder.CreateSelect(Cond, NarrowY, X, "narrow.sel", Op);
- return replaceInstUsesWith(FPT, Sel);
- }
}
if (auto *II = dyn_cast<IntrinsicInst>(FPT.getOperand(0))) {
|
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.
I think this LGTM, except maybe change NFCI to NFC in the title? I also looked at the subsuming commit, and I think we can be confident that this is an NFC.
Can you pre-commit this test: https://alive2.llvm.org/ce/z/XNQvu5
|
To guard against regression from #117182.
This case is doubly-blocked, first by llvm-project/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp Lines 176 to 184 in f81f47e
llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp Lines 1696 to 1709 in f81f47e
|
A complicating factor is that we perform this canonicalization: define float @t4(double %a) {
; CHECK-LABEL: @t4(
; CHECK-NEXT: [[DOTINV:%.*]] = fcmp oge double [[A:%.*]], 5.000000e+00
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[DOTINV]], double 5.000000e+00, double [[A]]
; CHECK-NEXT: [[TMP2:%.*]] = fptrunc double [[TMP1]] to float
; CHECK-NEXT: ret float [[TMP2]]
;
%1 = fcmp ult double %a, 5.0
%2 = fptrunc double %a to float
%3 = select i1 %1, float %2, float 5.0
ret float %3
} So just special casing fptrunc also doesn't work, because we'd infinite loop with this transform. So I'm inclined to just leave this alone... |
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.
LGTM. Remember to update the test f81f47e :)
@dtcxzyw But do we really want to merge this despite the regression? |
This pattern looks weird and should be caused by an unexpected upcasting. I believe it is easy to be fixed in the source code with the help of linters. BTW, before fixing the regression, we should fold So I agree that we just leave it alone. |
This was subsumed by FoldOpIntoSelect() in #116073, and has incorrect FMF propagation on top.