Skip to content

Commit 05e8466

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:658b655191e9 into amd-gfx:d68837a57682
Local branch amd-gfx d68837a Merged main:782f1a0d8956 into amd-gfx:b08b9d7e72fc Remote branch main 658b655 [clang][Interp][NFC] Refactor ByteCodeEmitter a bit
2 parents d68837a + 658b655 commit 05e8466

File tree

5 files changed

+128
-18
lines changed

5 files changed

+128
-18
lines changed

clang/lib/AST/Interp/ByteCodeEmitter.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,22 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
109109
// Return a dummy function if compilation failed.
110110
if (BailLocation)
111111
return llvm::make_error<ByteCodeGenError>(*BailLocation);
112-
else {
113-
Func->setIsFullyCompiled(true);
114-
return Func;
115-
}
116-
} else {
117-
// Create scopes from descriptors.
118-
llvm::SmallVector<Scope, 2> Scopes;
119-
for (auto &DS : Descriptors) {
120-
Scopes.emplace_back(std::move(DS));
121-
}
122112

123-
// Set the function's code.
124-
Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap),
125-
std::move(Scopes), FuncDecl->hasBody());
126113
Func->setIsFullyCompiled(true);
127114
return Func;
128115
}
116+
117+
// Create scopes from descriptors.
118+
llvm::SmallVector<Scope, 2> Scopes;
119+
for (auto &DS : Descriptors) {
120+
Scopes.emplace_back(std::move(DS));
121+
}
122+
123+
// Set the function's code.
124+
Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap),
125+
std::move(Scopes), FuncDecl->hasBody());
126+
Func->setIsFullyCompiled(true);
127+
return Func;
129128
}
130129

131130
Scope::Local ByteCodeEmitter::createLocal(Descriptor *D) {

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 475724
19+
#define LLVM_MAIN_REVISION 475727
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/IR/Function.h"
2626
#include "llvm/IR/GetElementPtrTypeIterator.h"
2727
#include "llvm/IR/IRBuilder.h"
28+
#include "llvm/IR/InstrTypes.h"
2829
#include "llvm/IR/Instructions.h"
2930
#include "llvm/IR/PatternMatch.h"
3031
#include "llvm/IR/Verifier.h"
@@ -748,11 +749,23 @@ void ConstraintInfo::transferToOtherSystem(
748749
default:
749750
break;
750751
case CmpInst::ICMP_ULT:
751-
// If B is a signed positive constant, A >=s 0 and A <s B.
752+
case CmpInst::ICMP_ULE:
753+
// If B is a signed positive constant, then A >=s 0 and A <s (or <=s) B.
752754
if (doesHold(CmpInst::ICMP_SGE, B, ConstantInt::get(B->getType(), 0))) {
753755
addFact(CmpInst::ICMP_SGE, A, ConstantInt::get(B->getType(), 0), NumIn,
754756
NumOut, DFSInStack);
755-
addFact(CmpInst::ICMP_SLT, A, B, NumIn, NumOut, DFSInStack);
757+
addFact(CmpInst::getSignedPredicate(Pred), A, B, NumIn, NumOut,
758+
DFSInStack);
759+
}
760+
break;
761+
case CmpInst::ICMP_UGE:
762+
case CmpInst::ICMP_UGT:
763+
// If A is a signed positive constant, then B >=s 0 and A >s (or >=s) B.
764+
if (doesHold(CmpInst::ICMP_SGE, A, ConstantInt::get(B->getType(), 0))) {
765+
addFact(CmpInst::ICMP_SGE, B, ConstantInt::get(B->getType(), 0), NumIn,
766+
NumOut, DFSInStack);
767+
addFact(CmpInst::getSignedPredicate(Pred), A, B, NumIn, NumOut,
768+
DFSInStack);
756769
}
757770
break;
758771
case CmpInst::ICMP_SLT:

llvm/test/Transforms/ConstraintElimination/signed-query-unsigned-system.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ define i1 @sge_no_const_unsigned_uge(i8 %a, i16 %b) {
109109
; CHECK-NEXT: call void @llvm.assume(i1 [[A_UGE_B]])
110110
; CHECK-NEXT: [[B_POS:%.*]] = icmp sge i16 [[B]], 0
111111
; CHECK-NEXT: call void @llvm.assume(i1 [[B_POS]])
112-
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i16 [[EXT]], [[B]]
113-
; CHECK-NEXT: ret i1 [[CMP]]
112+
; CHECK-NEXT: ret i1 true
114113
;
115114
%ext = zext i8 %a to i16
116115
%a.uge.b = icmp uge i16 %ext, %b

llvm/test/Transforms/ConstraintElimination/transfer-unsigned-facts-to-signed.ll

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,102 @@ then:
228228
else:
229229
ret i1 0
230230
}
231+
232+
define i1 @ule_signed_pos_constant_1(i8 %a, i8 %b) {
233+
; CHECK-LABEL: @ule_signed_pos_constant_1(
234+
; CHECK-NEXT: [[B_NON_NEG:%.*]] = icmp sge i8 [[B:%.*]], 0
235+
; CHECK-NEXT: call void @llvm.assume(i1 [[B_NON_NEG]])
236+
; CHECK-NEXT: [[A_ULE_B:%.*]] = icmp ule i8 [[A:%.*]], [[B]]
237+
; CHECK-NEXT: call void @llvm.assume(i1 [[A_ULE_B]])
238+
; CHECK-NEXT: [[SLT_TEST:%.*]] = icmp slt i8 [[A]], [[B]]
239+
; CHECK-NEXT: [[RESULT_XOR:%.*]] = xor i1 true, [[SLT_TEST]]
240+
; CHECK-NEXT: ret i1 [[RESULT_XOR]]
241+
;
242+
%b_non_neg = icmp sge i8 %b, 0
243+
call void @llvm.assume(i1 %b_non_neg)
244+
%a_ule_b = icmp ule i8 %a, %b
245+
call void @llvm.assume(i1 %a_ule_b)
246+
247+
%sle_test = icmp sle i8 %a, %b
248+
%slt_test = icmp slt i8 %a, %b
249+
%result_xor = xor i1 %sle_test, %slt_test
250+
251+
ret i1 %result_xor
252+
}
253+
254+
define i1 @ule_signed_pos_constant_2(i8 %a) {
255+
; CHECK-LABEL: @ule_signed_pos_constant_2(
256+
; CHECK-NEXT: [[A_ULT_4:%.*]] = icmp ule i8 [[A:%.*]], 4
257+
; CHECK-NEXT: br i1 [[A_ULT_4]], label [[THEN:%.*]], label [[ELSE:%.*]]
258+
; CHECK: then:
259+
; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, true
260+
; CHECK-NEXT: [[RES_2:%.*]] = xor i1 [[RES_1]], true
261+
; CHECK-NEXT: ret i1 [[RES_2]]
262+
; CHECK: else:
263+
; CHECK-NEXT: [[C_2:%.*]] = icmp sge i8 [[A]], 0
264+
; CHECK-NEXT: [[C_3:%.*]] = icmp sle i8 [[A]], 4
265+
; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[C_2]], [[C_3]]
266+
; CHECK-NEXT: [[C_4:%.*]] = icmp sle i8 [[A]], 5
267+
; CHECK-NEXT: [[RES_4:%.*]] = xor i1 [[RES_3]], [[C_4]]
268+
; CHECK-NEXT: ret i1 [[RES_4]]
269+
;
270+
%a.ult.4 = icmp ule i8 %a, 4
271+
br i1 %a.ult.4, label %then, label %else
272+
273+
then:
274+
%t.0 = icmp sge i8 %a, 0
275+
%t.1 = icmp sle i8 %a, 4
276+
%res.1 = xor i1 %t.0, %t.1
277+
278+
%c.0 = icmp sle i8 %a, 5
279+
%res.2 = xor i1 %res.1, %c.0
280+
ret i1 %res.2
281+
282+
else:
283+
%c.2 = icmp sge i8 %a, 0
284+
%c.3 = icmp sle i8 %a, 4
285+
%res.3 = xor i1 %c.2, %c.3
286+
287+
%c.4 = icmp sle i8 %a, 5
288+
%res.4 = xor i1 %res.3, %c.4
289+
290+
ret i1 %res.4
291+
}
292+
293+
define i1 @uge_assumed_positive_values(i8 %a, i8 %b) {
294+
; CHECK-LABEL: @uge_assumed_positive_values(
295+
; CHECK-NEXT: [[A_NON_NEG:%.*]] = icmp sge i8 [[A:%.*]], 0
296+
; CHECK-NEXT: call void @llvm.assume(i1 [[A_NON_NEG]])
297+
; CHECK-NEXT: [[A_UGT_B:%.*]] = icmp uge i8 [[A]], [[B:%.*]]
298+
; CHECK-NEXT: call void @llvm.assume(i1 [[A_UGT_B]])
299+
; CHECK-NEXT: ret i1 true
300+
;
301+
%a_non_neg = icmp sge i8 %a, 0
302+
call void @llvm.assume(i1 %a_non_neg)
303+
%a_ugt_b = icmp uge i8 %a, %b
304+
call void @llvm.assume(i1 %a_ugt_b)
305+
306+
%result = icmp sge i8 %a, %b
307+
308+
ret i1 %result
309+
}
310+
311+
define i1 @ugt_assumed_positive_values(i8 %a, i8 %b) {
312+
; CHECK-LABEL: @ugt_assumed_positive_values(
313+
; CHECK-NEXT: [[A_NON_NEG:%.*]] = icmp sge i8 [[A:%.*]], 0
314+
; CHECK-NEXT: call void @llvm.assume(i1 [[A_NON_NEG]])
315+
; CHECK-NEXT: [[A_UGT_B:%.*]] = icmp ugt i8 [[A]], [[B:%.*]]
316+
; CHECK-NEXT: call void @llvm.assume(i1 [[A_UGT_B]])
317+
; CHECK-NEXT: ret i1 true
318+
;
319+
%a_non_neg = icmp sge i8 %a, 0
320+
call void @llvm.assume(i1 %a_non_neg)
321+
%a_ugt_b = icmp ugt i8 %a, %b
322+
call void @llvm.assume(i1 %a_ugt_b)
323+
324+
%result = icmp sgt i8 %a, %b
325+
326+
ret i1 %result
327+
}
328+
329+
declare void @llvm.assume(i1)

0 commit comments

Comments
 (0)