Skip to content

Conversation

@linuxrocks123
Copy link
Contributor

This is to demonstrate that setOperationAction does not work to solve SWDEV-562122. See #165626

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/lib/Target/AMDGPU/SIISelLowering.cpp llvm/lib/Target/AMDGPU/SIISelLowering.h --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 95910b68f..de6394b76 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -181,7 +181,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
 
     // We don't want the default expansion of 16-bit ABS since we can
     // sign-extend and use the 32-bit ABS operation for 16-bit ABS with SGPRs
-    setOperationAction(ISD::ABS, {MVT::i8,MVT::i16}, Custom);
+    setOperationAction(ISD::ABS, {MVT::i8, MVT::i16}, Custom);
   }
 
   addRegisterClass(MVT::v32i32, &AMDGPU::VReg_1024RegClass);
@@ -7281,7 +7281,7 @@ static SDValue lowerLaneOp(const SITargetLowering &TLI, SDNode *N,
 void SITargetLowering::ReplaceNodeResults(SDNode *N,
                                           SmallVectorImpl<SDValue> &Results,
                                           SelectionDAG &DAG) const {
-  switch (N->getOpcode()) {    
+  switch (N->getOpcode()) {
   case ISD::INSERT_VECTOR_ELT: {
     if (SDValue Res = lowerINSERT_VECTOR_ELT(SDValue(N, 0), DAG))
       Results.push_back(Res);
@@ -7462,7 +7462,7 @@ void SITargetLowering::ReplaceNodeResults(SDNode *N,
   case ISD::ABS:
     if (N->getValueType(0) == MVT::i16 || N->getValueType(0) == MVT::i8) {
       SDValue result = lowerABSi16(SDValue(N, 0), DAG);
-      if(result!=SDValue()) {
+      if (result != SDValue()) {
         Results.push_back(result);
         return;
       }
@@ -16894,7 +16894,7 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
   switch (N->getOpcode()) {
   case ISD::ABS:
     if (N->getValueType(0) == MVT::i16 || N->getValueType(0) == MVT::i8)
-      return lowerABSi16(SDValue(N,0), DCI.DAG);
+      return lowerABSi16(SDValue(N, 0), DCI.DAG);
     break;
   case ISD::ADD:
     return performAddCombine(N, DCI);


// We don't want the default expansion of 16-bit ABS since we can
// sign-extend and use the 32-bit ABS operation for 16-bit ABS with SGPRs
setOperationAction(ISD::ABS, {MVT::i8,MVT::i16}, Custom);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be easier to ignore i8 for now and just get i16 working. i8 adds way more problems if you're having trouble with the easy case

@@ -7450,6 +7459,15 @@ void SITargetLowering::ReplaceNodeResults(SDNode *N,
Results.push_back(lowerFSQRTF16(SDValue(N, 0), DAG));
break;
}
case ISD::ABS:
if (N->getValueType(0) == MVT::i16 || N->getValueType(0) == MVT::i8) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i16 won't reach here in the relevant case. It would happen for <= gfx7

assert((Op.getValueType() == MVT::i16 || Op.getValueType() == MVT::i8) &&
"Tried to select abs i16 lowering with non-i16 type.");

// divergent means will not end up using SGPRs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stronger of an assertion than is true, it's just more likely

if (Op->isDivergent())
return SDValue();

//(abs i16 (i16 op1)) -> (trunc i16 (abs i32 (sext i32 (i16 op1))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//(abs i16 (i16 op1)) -> (trunc i16 (abs i32 (sext i32 (i16 op1))))
// (abs i16 (i16 op1)) -> (trunc i16 (abs i32 (sext i32 (i16 op1))))


// divergent means will not end up using SGPRs
if (Op->isDivergent())
return SDValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the opposite of what you want:

Suggested change
return SDValue();
return Op;

To get the default expansion, you return the original node. Return SDValue() means treat as legal

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants