[DAG] canCreateUndefOrPoison - fix missing argument typo We were missing the PoisonOnly argument (so Depth + 1 was being used instead and the default Depth = 0 argument then being silently used) Fixes #94145 and serves as the test case for 9e22c7a0ea87228dffcdfd7ab62724f72e0b3e30
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 3def51c..414c724 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5286,7 +5286,7 @@ // If the max shift amount isn't in range, then the shift can // create poison. return !isGuaranteedNotToBeUndefOrPoison(Op.getOperand(1), DemandedElts, - Depth + 1) || + PoisonOnly, Depth + 1) || !getValidMaximumShiftAmount(Op, DemandedElts, Depth + 1); case ISD::SCALAR_TO_VECTOR:
diff --git a/llvm/test/CodeGen/RISCV/pr94145.ll b/llvm/test/CodeGen/RISCV/pr94145.ll new file mode 100644 index 0000000..17e355a --- /dev/null +++ b/llvm/test/CodeGen/RISCV/pr94145.ll
@@ -0,0 +1,20 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc < %s -mtriple=riscv32-- | FileCheck %s +; RUN: llc < %s -mtriple=riscv64-- | FileCheck %s + +define i32 @PR94145(i16 %a0) { +; CHECK-LABEL: PR94145: +; CHECK: # %bb.0: +; CHECK-NEXT: andi a0, a0, 2 +; CHECK-NEXT: seqz a0, a0 +; CHECK-NEXT: li a1, 1 +; CHECK-NEXT: sll a0, a1, a0 +; CHECK-NEXT: ret + %lshr = lshr i16 %a0, 1 + %and = and i16 %lshr, 1 + %xor = xor i16 %and, 1 + %shl = shl i16 1, %xor + %freeze = freeze i16 %shl + %zext = zext i16 %freeze to i32 + ret i32 %zext +}