Skip to content

Commit

Permalink
Merge branch 'master' into virtual_function_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoppens authored Jan 13, 2024
2 parents cba313d + 1bc2950 commit 8c4c719
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Build
run: |
mkdir build
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-16/cmake
cmake --build build
- name: Test
Expand Down
6 changes: 6 additions & 0 deletions lib/Target/CBackend/CBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,7 @@ void CWriter::generateHeader(Module &M) {
case Intrinsic::trunc:
case Intrinsic::umax:
case Intrinsic::umin:
case Intrinsic::is_constant:
intrinsicsToDefine.push_back(&*I);
continue;
}
Expand Down Expand Up @@ -4654,6 +4655,9 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
case Intrinsic::umin:
Out << " r = a < b ? a : b;\n";
break;
case Intrinsic::is_constant:
Out << " r = 0 /* llvm.is.constant */;\n";
break;
}

} else {
Expand Down Expand Up @@ -4775,6 +4779,7 @@ bool CWriter::lowerIntrinsics(Function &F) {
case Intrinsic::dbg_declare:
case Intrinsic::umax:
case Intrinsic::umin:
case Intrinsic::is_constant:
// We directly implement these intrinsics
break;

Expand Down Expand Up @@ -5089,6 +5094,7 @@ bool CWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID) {
case Intrinsic::trap:
case Intrinsic::umax:
case Intrinsic::umin:
case Intrinsic::is_constant:
return false; // these use the normal function call emission
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/cpp_tests/test_is_constant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int f(int i) {
if (__builtin_constant_p(i) &&
i == 1) /* generates the llvm.is.constant.i32 intrinsic at -O0 */
return i + 5;
return 6;
}

int main() { return f(1); }

0 comments on commit 8c4c719

Please sign in to comment.