Skip to content

Commit 5400f43

Browse files
tuStromaigcbot
authored andcommitted
Avoid poison value while emulating "uitofp"
Replace shift amount from subtracting from 0 to subtracting from max shift amount
1 parent 6fc0896 commit 5400f43

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

IGC/Compiler/CISACodeGen/Emu64OpsPass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,8 @@ Value* InstExpander::convertUIToFP32(Type* DstTy, Value* Lo, Value* Hi, Instruct
15361536
// 0 < ShAmt < 32
15371537
Value* L = IRB->CreateShl(Lo, ShAmt);
15381538
Value* H = IRB->CreateShl(Hi, ShAmt);
1539-
Value* T0 = IRB->CreateLShr(Lo, IRB->CreateNeg(ShAmt));
1539+
Value* S = IRB->CreateSub(IRB->getInt32(32), ShAmt);
1540+
Value* T0 = IRB->CreateLShr(Lo, S);
15401541
H = IRB->CreateOr(H, T0);
15411542

15421543
InnerResHi->addIncoming(Hi, TrueBB);

IGC/Compiler/tests/Emu64Ops/converts.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ define void @test_uitofp(i64 %a) {
103103
; CHECK: .u2f.inner.true.branch:
104104
; CHECK: [[TMP7:%[A-z0-9]*]] = shl i32 [[TMP2]], [[TMP4]]
105105
; CHECK: [[TMP8:%[A-z0-9]*]] = shl i32 [[TMP3]], [[TMP4]]
106-
; CHECK: [[TMP9:%[A-z0-9]*]] = sub i32 0, [[TMP4]]
106+
; CHECK: [[TMP9:%[A-z0-9]*]] = sub i32 32, [[TMP4]]
107107
; CHECK: [[TMP10:%[A-z0-9]*]] = lshr i32 [[TMP2]], [[TMP9]]
108108
; CHECK: [[TMP11:%[A-z0-9]*]] = or i32 [[TMP8]], [[TMP10]]
109109
; CHECK: br label [[TMP12]]
@@ -153,7 +153,7 @@ define void @test_sitofp(i64 %a) {
153153
; CHECK: .u2f.inner.true.branch:
154154
; CHECK: [[TMP13:%[A-z0-9]*]] = shl i32 [[TMP8]], [[TMP10]]
155155
; CHECK: [[TMP14:%[A-z0-9]*]] = shl i32 [[TMP9]], [[TMP10]]
156-
; CHECK: [[TMP15:%[A-z0-9]*]] = sub i32 0, [[TMP10]]
156+
; CHECK: [[TMP15:%[A-z0-9]*]] = sub i32 32, [[TMP10]]
157157
; CHECK: [[TMP16:%[A-z0-9]*]] = lshr i32 [[TMP8]], [[TMP15]]
158158
; CHECK: [[TMP17:%[A-z0-9]*]] = or i32 [[TMP14]], [[TMP16]]
159159
; CHECK: br label [[TMP18]]

0 commit comments

Comments
 (0)