Skip to content

Commit 64937d2

Browse files
committed
remove unary since fneg only case. copy NUW or NSW over from orig binOp to new binOp.
1 parent 0a561f5 commit 64937d2

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

llvm/lib/Target/DirectX/DXILLegalizePass.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,21 @@ static bool fixI8TruncUseChain(Instruction &I,
7070
}
7171

7272
Value *NewInst = nullptr;
73-
if (auto *BO = dyn_cast<BinaryOperator>(&I))
73+
if (auto *BO = dyn_cast<BinaryOperator>(&I)) {
7474
NewInst =
7575
Builder.CreateBinOp(BO->getOpcode(), NewOperands[0], NewOperands[1]);
76-
else if (Cmp) {
76+
77+
if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(&I)) {
78+
if (OBO->hasNoSignedWrap())
79+
cast<BinaryOperator>(NewInst)->setHasNoSignedWrap();
80+
if (OBO->hasNoUnsignedWrap())
81+
cast<BinaryOperator>(NewInst)->setHasNoUnsignedWrap();
82+
}
83+
} else if (Cmp) {
7784
NewInst = Builder.CreateCmp(Cmp->getPredicate(), NewOperands[0],
7885
NewOperands[1]);
7986
Cmp->replaceAllUsesWith(NewInst);
80-
} else if (auto *UnaryOp = dyn_cast<UnaryOperator>(&I))
81-
NewInst = Builder.CreateUnOp(UnaryOp->getOpcode(), NewOperands[0]);
87+
}
8288

8389
if (NewInst) {
8490
ReplacedValues[&I] = NewInst;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define i32 @removal_only_test(i32 %a) {
1212
define i32 @i8trunc(float %0) #0 {
1313
; CHECK-LABEL: define i32 @i8trunc(
1414
; CHECK-NOT: %4 = trunc nsw i32 %3 to i8
15-
; CHECK: add i32
15+
; CHECK: add nsw i32
1616
; CHECK-NEXT: srem i32
1717
; CHECK-NEXT: sub i32
1818
; CHECK-NEXT: mul i32

0 commit comments

Comments
 (0)