Skip to content

Added ROLW/RORW/SLLW/SRAW/SRLW for canCreateUndefOrPoisonForTargetNode #152609

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

badumbatish
Copy link
Contributor

Fixes #149285.

@llvmbot
Copy link
Member

llvmbot commented Aug 7, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Jasmine Tang (badumbatish)

Changes

Fixes #149285.


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

1 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+8)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index adbfbeb4669e7..d86ec003459d3 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -21477,6 +21477,14 @@ bool RISCVTargetLowering::canCreateUndefOrPoisonForTargetNode(
 
   // TODO: Add more target nodes.
   switch (Op.getOpcode()) {
+  case RISCVISD::SLLW:
+  case RISCVISD::SRAW:
+  case RISCVISD::SRLW:
+  case RISCVISD::RORW:
+  case RISCVISD::ROLW:
+    // Only the lower 5 bits of RHS are read, guaranteeing the rotate/shift
+    // amount is bounds.
+    return false;
   case RISCVISD::SELECT_CC:
     // Integer select_cc cannot create poison.
     // TODO: What are the FP poison semantics?

@badumbatish badumbatish marked this pull request as draft August 7, 2025 23:00
@badumbatish
Copy link
Contributor Author

badumbatish commented Aug 7, 2025

The only place where I see this piece of code used is via visitFreeze in llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp.

But in visiting freeze (hoping to hit sllw), freeze is still wrapping sext and shl, not sllw yet.

Therefore I'm not sure if there's any other tests to be constructed. I'm also not sure what kind of visible effects can I test for here? i.e even if freeze unwraps itself for a sllw inside, how does that change the assembly?

Putting it as draft for now

Test case is

define i64 @shl(i32 %x, i32 %y) {
; CHECK64I-LABEL: shl:
; CHECK64I:       # %bb.0:
; CHECK64I-NEXT:    sllw a0, a0, a1
; CHECK64I-NEXT:    ret
  %m = and i32 %y, 31
  %s = shl i32 %x, %m
  %r = sext i32 %s to i64
  %hhhh = freeze i64 %r
  ret i64 %r
}

@badumbatish badumbatish requested review from lukel97 and topperc August 7, 2025 23:02
@badumbatish badumbatish marked this pull request as ready for review August 8, 2025 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RISCV] canCreateUndefOrPoisonForTargetNode - can ROLW/RORW + SLLW/SRAW/SRLW create undef/poison?
2 participants