[llvm] Zext sext undef in sdag (PR #115451)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 02:02:28 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
@llvm/pr-subscribers-backend-x86
Author: fengfeng (fengfeng09)
<details>
<summary>Changes</summary>
extend an undef value in sdag should keep the undef info.
---
Full diff: https://github.com/llvm/llvm-project/pull/115451.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+6-4)
- (modified) llvm/test/CodeGen/X86/zext-sext.ll (+10)
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 203e14f6cde3e3..fe7d4b9d7ccbf9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6224,8 +6224,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
return getNode(OpOpcode, DL, VT, N1.getOperand(0), Flags);
}
if (OpOpcode == ISD::UNDEF)
- // sext(undef) = 0, because the top bits will all be the same.
- return getConstant(0, DL, VT);
+ // sext(undef) = undef in a conservative way, because not all of the bits
+ // are zero and there is no mechanism tracking the undef part.
+ return getUNDEF(VT);
break;
case ISD::ZERO_EXTEND:
assert(VT.isInteger() && N1.getValueType().isInteger() &&
@@ -6244,8 +6245,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
return getNode(ISD::ZERO_EXTEND, DL, VT, N1.getOperand(0), Flags);
}
if (OpOpcode == ISD::UNDEF)
- // zext(undef) = 0, because the top bits will be zero.
- return getConstant(0, DL, VT);
+ // zext(undef) = undef in a conservative way, because not all of the bits
+ // are zero and there is no mechanism tracking the undef part.
+ return getUNDEF(VT);
// Skip unnecessary zext_inreg pattern:
// (zext (trunc x)) -> x iff the upper bits are known zero.
diff --git a/llvm/test/CodeGen/X86/zext-sext.ll b/llvm/test/CodeGen/X86/zext-sext.ll
index 25929ecbde76f1..766512afc2a7ec 100644
--- a/llvm/test/CodeGen/X86/zext-sext.ll
+++ b/llvm/test/CodeGen/X86/zext-sext.ll
@@ -77,5 +77,15 @@ entry:
%alphaXbetaY = add i64 %alphaX, %tmp115
%transformed = add i64 %alphaXbetaY, 9040145182981852475
store i64 %transformed, ptr %d, align 8
+ %tmp200 = zext i16 undef to i32
+ %tmp201 = zext i16 undef to i32
+ %tmp202 = shl i32 %tmp201, 16
+ %tmp203 = or i32 %tmp200, %tmp202
+ store i32 %tmp203, ptr %a, align 4
+ %tmp210 = sext i16 undef to i32
+ %tmp211 = sext i16 undef to i32
+ %tmp212 = shl i32 %tmp211, 16
+ %tmp213 = or i32 %tmp210, %tmp212
+ store i32 %tmp213, ptr %b, align 4
ret void
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/115451
More information about the llvm-commits
mailing list