Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SDAG] Minor cleanup to TargetLowering::expandFP_ROUND. NFC#193793

Open
davemgreen wants to merge 1 commit intollvm:mainfrom
davemgreen:gh-dag-cleanupexpandfpround
Open

[SDAG] Minor cleanup to TargetLowering::expandFP_ROUND. NFC#193793
davemgreen wants to merge 1 commit intollvm:mainfrom
davemgreen:gh-dag-cleanupexpandfpround

Conversation

@davemgreen
Copy link
Copy Markdown
Collaborator

Noticed when porting to GISel, constants might as well be added to the RHS of an add and a bitcast from the same type can be removed.

Noticed when porting to GISel, constants are better added to the RHS of an add
and a bitcast from the same type can be removed.
@davemgreen davemgreen requested review from RKSimon and arsenm April 23, 2026 16:19
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Apr 23, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Apr 23, 2026

@llvm/pr-subscribers-llvm-selectiondag

Author: David Green (davemgreen)

Changes

Noticed when porting to GISel, constants might as well be added to the RHS of an add and a bitcast from the same type can be removed.


Full diff: https://github.com/llvm/llvm-project/pull/193793.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp (+1-2)
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 2f069e7c1c90d..b7a43b4bf4cfc 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -12503,7 +12503,7 @@ SDValue TargetLowering::expandFP_ROUND(SDNode *Node, SelectionDAG &DAG) const {
                               DAG.getShiftAmountConstant(16, I32, dl));
     Lsb = DAG.getNode(ISD::AND, dl, I32, Lsb, One);
     SDValue RoundingBias =
-        DAG.getNode(ISD::ADD, dl, I32, DAG.getConstant(0x7fff, dl, I32), Lsb);
+        DAG.getNode(ISD::ADD, dl, I32, Lsb, DAG.getConstant(0x7fff, dl, I32));
     SDValue Add = DAG.getNode(ISD::ADD, dl, I32, Op, RoundingBias);
 
     // Don't round if we had a NaN, we don't want to turn 0x7fffffff into
@@ -12513,7 +12513,6 @@ SDValue TargetLowering::expandFP_ROUND(SDNode *Node, SelectionDAG &DAG) const {
     // Now that we have rounded, shift the bits into position.
     Op = DAG.getNode(ISD::SRL, dl, I32, Op,
                      DAG.getShiftAmountConstant(16, I32, dl));
-    Op = DAG.getNode(ISD::BITCAST, dl, I32, Op);
     EVT I16 = I32.changeElementType(*DAG.getContext(), MVT::i16);
     Op = DAG.getNode(ISD::TRUNCATE, dl, I16, Op);
     return DAG.getNode(ISD::BITCAST, dl, VT, Op);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants