Skip to content

Commit 0a561f5

Browse files
committed
allow non i32 imm values
1 parent 7d93231 commit 0a561f5

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

llvm/lib/Target/DirectX/DXILLegalizePass.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ static bool fixI8TruncUseChain(Instruction &I,
4848
Type *InstrType = IntegerType::get(I.getContext(), 32);
4949
for (unsigned OpIdx = 0; OpIdx < I.getNumOperands(); ++OpIdx) {
5050
Value *Op = I.getOperand(OpIdx);
51-
if (ReplacedValues.count(Op)) {
51+
if (ReplacedValues.count(Op))
5252
InstrType = ReplacedValues[Op]->getType();
53+
}
54+
for (unsigned OpIdx = 0; OpIdx < I.getNumOperands(); ++OpIdx) {
55+
Value *Op = I.getOperand(OpIdx);
56+
if (ReplacedValues.count(Op))
5357
NewOperands.push_back(ReplacedValues[Op]);
54-
} else if (auto *Imm = dyn_cast<ConstantInt>(Op)) {
58+
else if (auto *Imm = dyn_cast<ConstantInt>(Op)) {
5559
APInt Value = Imm->getValue();
5660
unsigned NewBitWidth = InstrType->getIntegerBitWidth();
5761
// Note: options here are sext or sextOrTrunc.
@@ -142,7 +146,7 @@ class DXILLegalizationPipeline {
142146
bool MadeChanges = false;
143147
for (auto &I : instructions(F)) {
144148
for (auto &LegalizationFn : LegalizationPipeline) {
145-
MadeChanges = LegalizationFn(I, ToRemove, ReplacedValues);
149+
MadeChanges |= LegalizationFn(I, ToRemove, ReplacedValues);
146150
}
147151
}
148152
while (!ToRemove.empty()) {

llvm/test/CodeGen/DirectX/legalize-i8.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,25 @@ define i32 @first_operand_imm_test(i32 %a) {
8585
%3 = sext i8 %2 to i32
8686
ret i32 %3
8787
}
88+
89+
define i16 @i16_test(i16 %a) {
90+
; CHECK-LABEL: define i16 @i16_test(
91+
; CHECK-SAME: i16 [[A:%.*]]) {
92+
; CHECK-NOT: trunc
93+
; CHECK: sub i16 0, [[A]]
94+
; CHECK-NOT: sext i8
95+
%1 = trunc nsw i16 %a to i8
96+
%2 = sub i8 0, %1
97+
%3 = sext i8 %2 to i16
98+
ret i16 %3
99+
}
100+
101+
define i32 @all_imm() {
102+
; CHECK-LABEL: define i32 @all_imm(
103+
; CHECK-NOT: trunc
104+
; CHECK-NOT: sext i8
105+
; CHECK: ret i32 -1
106+
%1 = sub i8 0, 1
107+
%2 = sext i8 %1 to i32
108+
ret i32 %2
109+
}

0 commit comments

Comments
 (0)